error: no matching function for call to 'std::basic_ifstream::open(std::string&)

  1. string filename = "1.txt";  
  2. ifstream fin;  
  3. fin.open(filename);  

上述語句會產生如下錯誤:

error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)

原因是C++的string類無法作爲open的參數。

解決方案:使用C的字符串。

例:

  1. char filename[10];  
  2. strcpy(filename, "1.txt");  
  3. ifstream fin;  
  4. fin.open(filename);  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章