开发者

Defining an output file stream within a class

How can I define an output file stream within a class, so that I don't have to keep passing it around to functions. Basically what I want to do is this:

class A {

private:
   ofstream otp ;

};

Then in my constructor, I simply have otp.open("myfile"); and in other functions I have otp.open("myfile", ios::app); , but it fails during compile time, 开发者_如何学编程saying:

../thermo.h(18): error: identifier "ofstream" is undefined
      ofstream otp ;

I have made sure to #include <fstream>

Thanks!


You'll need to use the fully qualified name, std::ofstream.


You need either place a using namespace std; statement above your class's declaration or declare the otp variable as std::ofstream because it exists within the std namespace.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜