Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

#include <fstream> vs #include <fstream.h> problem 1

Status
Not open for further replies.

chpicker

Programmer
Apr 10, 2001
1,316
I'm trying to learn the "proper" way to code to ANSI specifications which involves losing some habits. One of these is using the .h versions of standard header files. However, I've run into a problem which I can't figure out the solution to.

Here is a sample chunk of code. This is the "old way" of doing it:
Code:
#include <fstream.h>
void main() {
	ifstream cInfile("c:\\myfile.bin",ios::nocreate|ios::binary);
}
This compiles fine. However, the following does not:
Code:
#include <fstream>
using namespace std;
void main() {
	ifstream cInfile("c:\\myfile.bin",ios::nocreate|ios::binary);
}
When I attempt to compile this code, I get the following error:

error C2039: 'nocreate' : is not a member of 'basic_ios<char,struct std::char_traits<char> >'

If I take out the reference to "nocreate" and leave "binary" in there, it compiles just fine.

Is "nocreate" changed to something else in the standard headers? Or is this a problem with the MS headers? I'm using Visual C++ 6.0 with SP4.

Ian
 
I googled nocreate and fstream and got this as the first result. It should be enough to help you with your problems.


Oh, and by the way, if you want to follow ANSI specifications don't forget to use int main() instead of void main(). You don't have to actually return a value, since the standard specifies that the main function (and only the main function) will return 0 by default if no return value is specified.
 
Cool, thanks!

And yeah, I always use int main(argc,argv), but when I post code here I try to keep it simple. In my experience, though, Visual C++ actually throws an error if you don't return a value from main() when you declare it int. *shrugs*

And yes, that solved my problem quite nicely. Strange how I didn't think to use Google. I'm continually amazed by the kinds of things I can find there.

Ian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top