Reputation: 1141
HI,
I am converting my project from vc6 to latest using vs 2010. I get problem on compiling my code
Error 931 error C2065: 'ostrstream' : undeclared identifier 1100 IntelliSense: identifier "fstream" is undefined
I have included the required files as told in Google
#if ! defined(_FSTREAM_)
#include <fstream>
#endif
#if ! defined(_STRSTREAM_)
#include <strstream>
#endif
When i press F12 on the fstream or ostrstream it takes to the respective files where these class are defined. Is there any other includes i have to do, i have been searching for this for long time with no luck :(
Thanks
Arvind
Upvotes: 3
Views: 12909
Reputation: 83
Without using namespace std;
as its good practice.
#include<fstream>
std::fstream fileio;
Where the fileio
is the object created by fstream. The fstream class needs to be created using the std keyword as it is part of the standard library.
Hence using : using namespace std;
in the code makes it work.
NOW using using namespace std;
can cause conflicts in shared libraries.
#include <fstream>
using namespace std;
fstream fileio;
Upvotes: 1
Reputation: 780
What worked for me was a combination of two answer. After some trial and error, fstream squiggly red lines vanished when I added,
#include <fstream>
using namespace std;
Upvotes: 0
Reputation: 71
Add these to your library list:
#include <stdio.h>
using namespace std;
Upvotes: 6
Reputation: 1810
Forget all the preprocessor stuff; it's redundant at best (the files in questiion will have reinclusion guards) and at worst an error (you're assuming the #defines used, which are arbitary). Just use code like this:
#include <fstream>
#include <strstream>
Also note that the strstream header is deprecated. You should use sstream instead, but note the newer classed in this file word differently to the deprecated ones).
Upvotes: 1