justin_______

So I decided to compile a few of my programs in Visual Studio 2005. But the same code that worked in VC++7 does not seem to be working. So I created a small test app and the same problem occurs. The output of this program is -1. The VC++ Help Search says this means fstream.fail() is true so is the file not even being opened I cannot figure out what is wrong here.


Re: Visual C++ General VC++8 fstream problem

Nishant Sivakumar

Perhaps there are spaces in your filename argument. If so, try putting the full path in quotes.




Re: Visual C++ General VC++8 fstream problem

Sdi

Did you step through the program in the debugger Specifically, to see what file you're trying to open



Re: Visual C++ General VC++8 fstream problem

justin_______

Nishant Sivakumar wrote:
Perhaps there are spaces in your filename argument. If so, try putting the full path in quotes.

This is not the problem since I was already doing this. Also I tried drag/dropping from the shell which means this is not a typo.

Sdi wrote:
Did you step through the program in the debugger Specifically, to see what file you're trying to open

0x003551b9 "C:\Documents and Settings\Justin\My Documents\Visual Studio 2005\Projects\Wad Tools\Show_Wad\Make_Wad.exe.wad" The debugger says this, the file I was trying to open.

Also, when I do this with the release build of the program I get a weird message that says " The application has requested the runtime to terminate it in a unusual way "






Re: Visual C++ General VC++8 fstream problem

Simple Samples

The following is the way I would write the program, and this works for me. I have excluded portions of the program that are not affected. Note that I usually write out the filename, at least when I initially write the program, so it is easy to see the filename and such. Also, it is important to test the file to ensure the open is successful before proceeding in the program.

Code Snippet
fstream in;
if (argc != 2) {
cout << "There are too few or too many arguments\n";
return 1;
}
cout << "Opening " << argv[1] << '\n';
in.open(argv[1], ios::in | ios::binary);
if (!in.is_open()) {
cout << "The file did not open\n";
return 1;
}
in.seekg(0, ios::end);
cout << endl << in.tellg() << endl;
in.seekg(0, ios::beg);