error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
2014-09-04 17:46
567 查看
[cpp] view
plaincopyprint?
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
plaincopyprint?
char filename[10];
strcpy(filename, "1.txt");
ifstream fin;
fin.open(filename);
plaincopyprint?
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
plaincopyprint?
char filename[10];
strcpy(filename, "1.txt");
ifstream fin;
fin.open(filename);
相关文章推荐
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- no matching function for call to ‘std::basic_string<char>::assign(std::string&, int)
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- 【求助】 no matching function for call to `strcpy(std::string&, char*&)'
- Qt error ------ no matching function for call to QObject::connect(QSpinBox*&, <unresolved overloaded function type>, QSlider*&, void (QAbstractSlider::*)(int))
- error: no matching function for call to ‘ptr_fun(<unresolved overloaded function type>)’
- error: no matching function for call to 'MainWindow::connect(*&, ...)
- error: no matching function for call to ‘boost::thread::thread(<unresolved overloaded function type>
- implicit instantiation of undefined template 'std::basic_stringstream<char,std::char_trats<char>,std
- no matching function for call to 'strstr(stdstring&, const char [4])'
- G++编译错误 no matching function for call to '_tag_data_value::StringAddLen(std::string, int, int)
- error C2678 binary '<' : no operator found for map<std::string, shared_ptr<Foo>>
- caffe编译Matlab接口报错:208: 4: error: no matching function for call to remove_if
- error: no matching function for call to 'std::exception:exception(const char[16])
- error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _T
- error: no matching function for call to 'std::exception:exception(const char[16])'
- error LNK2005: "public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char>
- error LNK2005: "public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::`v
- : error: undefined reference to `cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_t