- string filename = "1.txt";
- ifstream fin;
- fin.open(filename);
上述語句會產生如下錯誤:
error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
原因是C++的string類無法作爲open的參數。
解決方案:使用C的字符串。
例:
- char filename[10];
- strcpy(filename, "1.txt");
- ifstream fin;
- fin.open(filename);