+ 3

Why do i get an error? And how do i fix it without actually writing "file.txt" in the argument?

string s = "file.txt"; ifstream myfile(s);

14th Jan 2018, 9:02 AM
chris
chris - avatar
4 Respuestas
+ 3
@~swim~ that was not the problem. The problem was that the function open takes in a const char* filename. To fix that i need char s[] = "file.txt";
18th Jan 2018, 5:18 PM
chris
chris - avatar
0
You getting an error because ifstream constructor expecting const char*, use c_str() to convert it to c string. myfile(s.c_str());
14th Jan 2018, 9:24 AM
Cain Eviatar
Cain Eviatar - avatar