weird problem on visual studio

Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

weird problem on visual studio

 
0
  #1
Mar 25th, 2007
hi, i have this simple code, that compiles on visual studio 2005.When i try to run the executable through visual studio {pressign ctrl+F5} it does nothing{although the test.txt has size of 1kb}, when i run the exe through the command prompt the program works fine...

Does anyone know why this is happening??
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. int main ()
  7. {
  8. long start,end;
  9. ifstream myfile ("test.txt", ios::in|ios::binary);
  10. start = myfile.tellg();
  11. myfile.seekg (0, ios::end);
  12. end = myfile.tellg();
  13. myfile.close();
  14. cout << "size of " << "test.txt";
  15. cout << " is " << (end-start) << " bytes.\n";
  16. return 0;
  17. }

thanks for your time,
NA
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: weird problem on visual studio

 
0
  #2
Mar 25th, 2007
VC closes the console window when the program ends. If you want to see the program's output you have to add something before the return to make the program wait for you to press a key before continuing. calling cin.ignore() just before the return statement will accomplish that.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,131
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 283
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: weird problem on visual studio

 
0
  #3
Mar 25th, 2007
Originally Posted by n.aggel View Post
hi, i have this simple code, that compiles on visual studio 2005.When i try to run the executable through visual studio {pressign ctrl+F5} it does nothing{although the test.txt has size of 1kb}, when i run the exe through the command prompt the program works fine...

Does anyone know why this is happening??
The program opens a window, runs very quickly, finishes, then closes the window. Add cin.getline() just before the return
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Join Date: Nov 2006
Posts: 202
Reputation: n.aggel is an unknown quantity at this point 
Solved Threads: 11
n.aggel's Avatar
n.aggel n.aggel is offline Offline
Posting Whiz in Training

Re: weird problem on visual studio

 
0
  #4
Mar 25th, 2007
Originally Posted by WaltP View Post
The program opens a window, runs very quickly, finishes, then closes the window. Add cin.getline() just before the return
Originally Posted by Ancient Dragon View Post
VC closes the console window when the program ends. If you want to see the program's output you have to add something before the return to make the program wait for you to press a key before continuing. calling cin.ignore() just before the return statement will accomplish that.

i don't want to read any input...the console window doesn't close....Just the output that appears is wrong...

The program that i posted simply reports the size of file..it doesn't need any interaction from the console....
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,662
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1502
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: weird problem on visual studio

 
0
  #5
Mar 25th, 2007
>>it doesn't need any interaction from the console

Yes it does if you want to keep the console window from closing. Try what we suggested and you will see why it is needed.
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: May 2006
Posts: 3,131
Reputation: WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of WaltP has much to be proud of 
Solved Threads: 283
Moderator
WaltP's Avatar
WaltP WaltP is offline Offline
Posting Sensei

Re: weird problem on visual studio

 
0
  #6
Mar 26th, 2007
Originally Posted by n.aggel View Post
i don't want to read any input...the console window doesn't close....Just the output that appears is wrong...

The program that i posted simply reports the size of file..it doesn't need any interaction from the console....
Oh? That's not what the other post said. We were answering this problem:
Originally Posted by n.aggel View Post
When i try to run the executable through visual studio {pressign ctrl+F5} it does nothing{although the test.txt has size of 1kb}, when i run the exe through the command prompt the program works fine...
"it does nothing" is not the same as "output that appears is wrong"

Therefore, start over and describe the problem in detail.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 2793 | Replies: 5
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC