Cannot use ofstream from fstream...

Started by
2 comments, last by bah 18 years, 7 months ago
Hi, I want to use ofstream from <fstream> but the compiler won't let me. The following is the class definition: <code> class DebugManager { private: ofstream m_log; bool m_ready; public: DebugManager(); virtual ~DebugManager(); friend void DebugManager_Write(...); }; </code> The first error, C2146, is at the line where m_log is defined and that starts an avalanche of other errors.
Advertisement
Try std::ofstream or use a using directive.
Try using std::ofstream, or typing using namespace std; outside the class.
What this mean is that ofstream is in the std namespace, and you must tell your compiler that you want to access ofstream from the namespace std. By typing out using namespace std; somewhere at the top of your page you tell the rest of that page to use the std namespace by default, and you can write ofstream m_log instead of std::ofstream m_log.
----------------------------------------------------------------------------------------------------------------------"Ask not what humanity can do for you, ask what you can do for humanity." - By: Richard D. Colbert Jr.
Thanks SiCrane, it works fine now. I should have remembered to include the namespace. :)

This topic is closed to new replies.

Advertisement