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

来源:互联网 发布:javascript动画 编辑:程序博客网 时间:2024/05/22 15:09

原文地址:  http://blog.csdn.net/cs_zlg/article/details/8300124

[cpp] view plain copy
 print?
  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的字符串。

例:

[cpp] view plain copy
 print?
  1. char filename[10];  
  2. strcpy(filename, "1.txt");  
  3. ifstream fin;  
  4. fin.open(filename);  

0 0
原创粉丝点击