Declaring ofstream variable in Visual Studio 2010

Hey,
How do you declare a variable as ofstream type in Visual Studio 2010.
I have the following and am getting an error stating:syntax error:missing; before identifer m_Log.
 
ofstream m_Log;


When I write this same code in Visual Studio C++ 6.0, I don't get an error.
Any help will be appreciated!!
Thanks in Advance!!
Did you #include <fstream> and add using namespace std; or using std::ofstream; ?
Last edited on
Thanks,
I included using std::ofstream;
Visual Studio 6.0 comes from a time when C++ looked a lot like C.
Nowadays the header files with an .h extension are deprecated and only there for compatibility. Also heavy use is made of namespaces (see this http://www.cplusplus.com/doc/tutorial/namespaces/ ).

Anyway, you need to
1
2
3
#include <fstream> // notice lack of ".h"

std::ofstream m_Log; // if you use one of hamsterman's "using" directives you can omit the "std::" 


Edit: I should type faster...
Last edited on
Topic archived. No new replies allowed.