Archived

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

Sand_Hawk

ifstream/ofstream are both creating a file...

Recommended Posts

Sand_Hawk    108
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
Guest Anonymous Poster   
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
Fruny    1658
quote:
Original post by Anonymous Poster
ios::noreplace fails if the file exists..
use ios::nocreate, which will fail if the file doesn''t exist.



These flags do not exist in standard C++.

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

Share this post


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

Share this post


Link to post
Share on other sites
Fruny    1658
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