ofstream & ifstream

hi , i am trying to open the file.
The code i am having the problem is

1
2
3
4
5
6
7
8
inline void CStance::assure(std::ofstream &in, const char *filename)
 {
	 using namespace std;
	 if(!in)
	{
		fprintf(stderr,"\nCannot open the file\n", filename); 
	}
 }


I am getting the error as

'std::ofstream' does not define this operator or a conversion to a type acceptable to the predefined operator



Any suggestion as why i am getting the error.
Thanks in advance !
You have not posted the code causing the problem.

I do not know why you are naming an output file stream "in", but that looks like a recipe for disaster. And, I suspect, is the root cause for your error...

Good luck!
I'm not sure why that code would produce that error. Maybe it is something that is happening earlier on the the file?

One thing I would say is that you don't need to use old type fprintf() with new style streams.

You could just say:

 
std::cerr << "\nCannot open the file\n" << filename; // much more C++ than C. 
You are right Galik .. silly mistak from my side . While checking again the code i got the problem .

I had not included fstream.h ...

Thanks both of you for the suggestions.
bluecoder -- you should include <fstream> not fstream.h the .h system libs are depricated, and can be non-portable.
Yes .. you are right idbentley . i have included <fstream> and it solved my problem.
Thanks.
Topic archived. No new replies allowed.