I've been trying for to make a program in MS Visual C++ that will open a preexisting file in binary mode, and read a value from it. The project compiles, but fails to function. No matter what I've tried I can't seem to get it to open a file. Here is the code less one data structure (long!) and the include files for brevity's sake:
I suspect that what is happening is that you are inadvertently setting the eof bit on line 31. So *memblock actually did read fine. But since GameStream.eof() is now true, further I/O is not possible until you say: GameStream.clear();
Thanks Duoas for reply, but not sure program is getting that far into the code. When I run debug, it automatically steps to the 'else' condition of the if statement on line 24. It seems as though the file can't be found, regardless of project directory I put it into. I've tried the debug directory etc, all to no avail. I've even deleted the file extension in case it was somehow interfering with my opening routine. Any other ideas?
Try setting gamefile to the full path of where you file is rather than just the file name. That way you'll know if the program can't find the file or if you have another problem like permissions.
Hey All, I got the file to work. Answer was problem with string not being opened and required the use of '.cstr()' to appended to end of 'gamefile' to allow it to find the file. Program works now and can read Hero.CharName correctly but now on to new issue. I'll post to a new thread to avoid mixing issues. :-) Thanks everyone for input.
You confuse me, your solution above (about use of .cstr()) does not seem to apply to the code you have posted.
In the code you have posted gamefile is a char array not a string type so the code you posted (should) work.