您的位置:首页 > 运维架构

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

2016-05-20 20:37 751 查看
原文地址: http://blog.csdn.net/cs_zlg/article/details/8300124
[cpp] view
plain copy

print?

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的字符串。

例:

[cpp] view
plain copy

print?

char filename[10];

strcpy(filename, "1.txt");

ifstream fin;

fin.open(filename);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: