opening a file

My problem is I try to call outGameFile.open("GameData.txt");

only I replace "GameData.txt" with a variable that equals it.

1
2
3
4
string file;
file = "GameData.txt";

outGameFile.open(file);


and then I get this error:
1
2
3
4
5
6
7
1>c:\users\owner\documents\visual studio 2008\projects\pong\pong\savegame.cpp(28) : error C2664: 'void std::basic_ofstream<_Elem,_Traits>::open(const wchar_t *,std::ios_base::openmode,int)' : cannot convert parameter 1 from 'std::string' to 'const wchar_t *'
1>        with
1>        [
1>            _Elem=char,
1>            _Traits=std::char_traits<char>
1>        ]
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called


Any help on what I can do to avoid this error would be appreciated!
open takes a const char* as a parameter, not a string

The good news is, if you have a string, you can get a const char* with the c_str function:

 
outGameFile.open( file.c_str() );
oh wow thank you!
1
2
3
string getfile = User.getFile();

	outGameFile.open( getfile.c_str() );
Topic archived. No new replies allowed.