Why is it saying that ios::noreplace is not a member of 'std::basic_ios<_Elem, _Traits>'
I read in MSDN help files that it is no longer defined in the new library files.
Where is it defined? or what value does it hold?
Why is it saying that ios::noreplace is not a member of 'std::basic_ios<_Elem, _Traits>'
I read in MSDN help files that it is no longer defined in the new library files.
Where is it defined? or what value does it hold?
One result from a search on the term ios::noreplace.
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
ok
thanks
But now i get a different error..
Code:ifstream blah; if(!(blah.open("blah.txt"))) { blah blah(); } ERROR: blah.cpp(33): error C2171: '!' : illegal on operands of type 'void' aslo: blah.cpp(33): error C2451: conditional expression of type 'void' is illegal Expressions of type void cannot be converted to other types
ERROR:Code:ifstream blah; if(!(blah.open("blah.txt"))) { blah blah(); }
blah.cpp(33): error C2171: '!' : illegal on operands of type 'void'
aslo:
blah.cpp(33): error C2451: conditional expression of type 'void' is illegal
Expressions of type void cannot be converted to other types
The error tells you exactly what is going on. The return type of the open file stream member function is type void. You can't perform a logical not (!) on a type void. It doesn't make any sense. This is what the messages are telling you.
Try using the is_open member function instead:
Or this (a little bit of a shortcut):Code:ifstream blah; blah.open("blah.txt"); if(!blah.is_open()) { blah blah(); }
Code:ifstream blah("blah.txt"); if(!blah.is_open()) { blah blah(); }
"Owners of dogs will have noticed that, if you provide them with food and water and shelter and affection, they will think you are god. Whereas owners of cats are compelled to realize that, if you provide them with food and water and shelter and affection, they draw the conclusion that they are gods."
-Christopher Hitchens
It doesn't work for some reason!
The file is there but it still executes the code in the if statement!
also when i try to write from file to a string it doesn't do anything
But when i run it nothin shows up?Code:string str, str1; ifstream blah("blah.txt"); blah >> str1 >> str2; cout << str1 << str2; Content of 'blah.txt': Text1 Text2
Last edited by mrafcho001; 06-05-2005 at 09:56 AM.
Always check for success when doing input or opening a file:
If you get the error then the most likely problem is that the file isn't where the program is looking for it. And if the file can't be opened, the stream is not in a good state, therefore any attempt to read from it will do nothing.Code:ifstream blah("blah.txt") if (!blah) { std::cerr<<"Error opening file\n"; // Do something, probably terminate }
My best code is written with the delete key.
Thanks guys
Just last question (I know, sorry)
Why doesn't the ifstreammembers accept strings?
or the string.c_str()?
Is there anyway to use a strings with the ifstream members?
How do i store everything in the file in 1 string?
Last edited by mrafcho001; 06-05-2005 at 01:39 PM.
string mystring; <--- mystring is a class object
whereas
char mycstring[42]; <--- is just an array of characters
so when you do stuff like
.open( ) is expecting a null terminated array of characters.. A string class variable can normally simulate this using overloaded <<, >>, =, +=, [], and == operators. But on occasions where a function is expecting a null terminated character array, you can call the c_str( ) funtion from your derived string class variable and it will return a pointer to a null terminated character array.Code:myifstream.open(mystring); // open( ) doesn't know / isn't prototyped to accept a string class variable
So it's just a matter of one object being a class object vs. one being a simple array
- "Problem Solving C++, The Object of Programming" -Walter Savitch
- "Data Structures and Other Objects using C++" -Walter Savitch
- "Assembly Language for Intel-Based Computers" -Kip Irvine
- "Programming Windows, 5th edition" -Charles Petzold
- "Visual C++ MFC Programming by Example" -John E. Swanke
- "Network Programming Windows" -Jones/Ohlund
- "Sams Teach Yourself Game Programming in 24 Hours" -Michael Morrison
- "Mathmatics for 3D Game Programming & Computer Graphics" -Eric Lengyel
>> Why doesn't the ifstreammembers accept strings? or the string.c_str()?
It does accept the result of .c_str(). If it isn't working for you, post the code and error.
Also, make sure you #include <string> for the string class. If you were trying to use ios::noreplace from <fstream.h> you might have incorrectly been trying to use <string.h>.
Last edited by Daved; 06-05-2005 at 11:11 PM.