Jump to content
  • Advertisement

Archived

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

Sand_Hawk

ifstream/ofstream are both creating a file...

This topic is 5712 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

I am using ofstream/ifstream objects for file access. But when I use this code:
ifstream FromFile("From.cpp");
ofstream ToFile("To.cpp", ios::noreplace);
 
If From.cpp doesn''t exist it gets created. But I don''t want the file to be created. What am I doing wrong? Sand Hawk ---------------- -Earth is 98% full. Please delete anybody you can.
My Site

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
ios::noreplace fails if the file exists..

use ios::nocreate, which will fail if the file doesn''t exist.


:D ~z~ :D

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
I thought that, but wasn''t sure. Thanx for the info.

Share this post


Link to post
Share on other sites
Not with std::fstream, std::ifstream, nor with std::ofstream, which are the only standard file stream classes, they don't.

std::ifstream ifs( "foo.txt" ) would simply not create the file, but just fail (i.e. ifs.bad() would be true).

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on October 3, 2002 2:01:37 PM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!