I get this odd compile error:
21 C:\programs\testspil\testspil.cpp `noreplace' is not a member of type `
help appreciatedCode:line 21: ofstream a_file("wins.txt", ios::noreplace);
Printable View
I get this odd compile error:
21 C:\programs\testspil\testspil.cpp `noreplace' is not a member of type `
help appreciatedCode:line 21: ofstream a_file("wins.txt", ios::noreplace);
>I get this odd compile error
It's hardly odd at all. noreplace is not standard C++, so you're probably using a compiler that doesn't support it. Think about why you're trying to use noreplace and see if you really need it. Chances are that you don't. :)
how else would you check if the file is already there? It's a statistics file where I want to store int's... So if it's the first time running the program then it should create a statistics file, but if it's already there I don't want to trunctate it...
So use ios::app then. Have a look at this page for the different flags.
>how else would you check if the file is already there?
Use something nonportable and implementation-dependent that we can't describe because you haven't give us any more detail about your compiler. Or you could simply open the file for reading. If the open is successful then the file exists, if it fails you'll simply have to assume it did so because the file doesn't yet exist. ;)
>but if it's already there I don't want to trunctate it...
See? You didn't really need noreplace after all, just use ios_base::app. :)
Is it recommended to use ios::app or ios_base::app?
>Is it recommended to use ios::app or ios_base::app?
ios_base::app is recommended simply because the C++ standard makes no mention of ios::app being valid that I can remember. :)
That's a good enough reason for me then. :p
If you don't mind, I'll correct myself before someone else does. After looking at the standard, both are valid. ios_base is where the openmode app is defined, but ios is a typedef defined asQuote:
Originally Posted by Prelude
Where basic_ios is a template class derived from ios_base. So both will work, both are standard, and which you use looks to be a matter of style. ;)Code:typedef basic_ios<char> ios;
Gah! Prelude was wrong! The world's going to heck in a handbasket!
Not wrong, just not completely correct :)
>Not wrong, just completely correct
I'm guessing you missed a 'not' in there.
/whistle Whatcha mean?
I use Bloodshed Dev-C++
thx for the help, but...
in line 25 below:
is there a voide value that isn't ignored?Code:23 ifstream winfilein;
24
25 if(!(winfilein.open("wins.txt", ifstream::in)))
26 {
27 winfilein.close();
28 blahblah;
29 }
I've looked up the function, but it seemed perfectly fine...
Is it because of the IF statement?
It is perfectly fine.