Getting conversion error when trying to open ofstream

Hello, I have this bit of code

1
2
ofstream infoFile;
infoFile.open(".masterpassword/" + username + ".mpdat", ios::out);


username is a string. When I run this, I get

1
2
3
4
5
6
7
main.cpp:132:17: error: no viable conversion from 'basic_string<char,
      std::char_traits<char>, std::allocator<char>>' to 'const char *'
                infoFile.open(".masterpassword/" + username + ".mpdat", ...
                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/include/c++/4.2.1/fstream:648:24: note: passing argument to parameter '__s'
      here
      open(const char* __s,


This is quite odd. When I just pass it normally, like ".masterpassword/plazmotech.mpdat" I don't get an error. I've tried assigning it to a string variable and it too doesn't work.

Thanks!
Can't do this.

"STRING A" + stringtype + "STRING B".

Try string(".masterpassword/")+ username + string(".mpdat")

-blueberry
Topic archived. No new replies allowed.