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??

#include <iostream>
#include <fstream>

using namespace std; 

int main () 
{
 long start,end;
 ifstream myfile ("test.txt", ios::in|ios::binary);
 start = myfile.tellg();
 myfile.seekg (0, ios::end);
 end = myfile.tellg();
 myfile.close();
 cout << "size of " << "test.txt";
 cout << " is " << (end-start) << " bytes.\n";
 return 0;
}

thanks for your time,
NA

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.

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 program opens a window, runs very quickly, finishes, then closes the window. Add cin.getline() just before the return

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....

>>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.

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:

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.

This article has been dead for over six months. Start a new discussion instead.