这有效:
file.open("Levels\\test.txt");
Run Code Online (Sandbox Code Playgroud)
这不是:
string pathname = "Levels\\test.txt";
file.open(pathname);
Run Code Online (Sandbox Code Playgroud)
它输出以下错误:
no matching function for call to 'std::basic_ifstrea<char, std::char_traits<char> >::open
(std::string&)'
Run Code Online (Sandbox Code Playgroud)
该成员函数需要a char const*而不是a std::string; 你需要通过它pathname.c_str().
(在C++ 0x中,有一个重载open,需要一个std::string,所以你的代码将在某一天工作;你的实现显然不支持这个.)