Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


How do you use fstream's file.open?

This topic is 6725 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

fstream file; file.open ".\\data\\tstfile.txt",ios::in/ios::nocreate ); if ( !file ) { MessageBox( NULL, "No File", "INFO", NULL ); return 0; } I want to open file ''data/tstfile.txt'' and it says ''NO FILE''.

Share this post

Link to post
Share on other sites

fstream file;
//insert relevant Error message
return 0;

As far as I know ios::in is the default mode argument. And ios::nocreate should work even though I can`t find anything on it right now.

Share this post

Link to post
Share on other sites
ios::in is only the default if you use ifstream and not fstream.
The default for fstream, as stated in the stl documentation for VC6 is
ios::in // ios:: out  

If you are opening a file for reading, you do not need to specify nocreate. I may be wrong here, but as long as it's input, it will fail if the file does not exist and not try to open one, so ios::nocreate seems redundant.

ifstream inStream;


if ( !inStream )
cerr << "Unable to open file." << endl;

The above should work.

From the code that you submitted, I would assume that you only want to open a file for reading. If so, use ifstream instead of fstream. If you need to read/write then use fstream.

There is nothing wrong with using fstream though for either situation.

If my pipe doesn't work, could someone tell me how to display a single pipe. I tried using a double pipe to see what would happen.


Edited by - AlekM on June 22, 2000 2:33:50 PM

Share this post

Link to post
Share on other sites
file.open( ".\\data\\tstfile.txt",ios::in/ios::nocreate );

if the / is a binary-or, your file may be placed incorrect.

when "compiling" is has to be in the work folder of your project. If you run the the exe manually it has to to in the debug/release dir.

eg in msvc++.


if you run manually:

if you have done this, and it still dosn''t work. Try taking properties on the file, and see if its not named tstfile.txt.txt
. notepad likes to f*** it up.

add a /ios::binary to read binary files. (/ is also a binary-or)

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!