error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
2012-12-15 23:23
676 查看
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);
相关文章推荐
- 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&)
- error: no matching function for call to 'std::basic_ifstream<char>::open(std::string&)
- implicit instantiation of undefined template 'std::basic_stringstream<char,std::char_trats<char>,std
- error C2027: 使用了未定义类型 std::basic_ifstream<_Elem,_Traits>
- 二进制“<<”: 没有找到接受“const std::basic_string<char,std::char_traits<char>,std::allocator<char>>”类型的右操作数的运算
- "std::basic_stringbuf<char, std::char_traits<char>, std::allocator<char> >::str() const"问题的解决办法
- error LNK2005: "public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char> >::`v
- error: 'std::basic_streambuf<_CharT, _Traits>::basic_streambuf(const std::basic_streambuf<_CharT, _T
- error LNK2005: "public: void __thiscall std::basic_ofstream<char,struct std::char_traits<char>
- iOS出现 Undefined symbols for architecture armv7 std::basic_string<char, std::char_traits<char>
- 编译osgAudio遇到的'std::basic_ifstream<char,std::char_traits<char>>' : base class undefined
- : error: undefined reference to `cv::VideoCapture::open(std::__cxx11::basic_string<char, std::char_t
- error C2514: “std::basic_stringstream<_Elem,_Traits,_Alloc>”: 类没有构造函数
- no matching function for call to ‘std::basic_string<char>::assign(std::string&, int)
- 报错"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::at(unsigne
- 【CString与string转换】不存在从 "LPWSTR" 转换到 "std::basic_string<char, std::char_traits<char>, std::allocator(转)
- cin, cout, ifstream, ofstream, istringstream, ostringstream, <iomanip>
- C++ 不能通过‘...’传递有不能平凡复制的类型‘const string {aka const class std::basic_string<char>}’
- error C2079: 'lstr' uses undefined class 'std::basic_stringstream<_Elem,_Traits,_Alloc>'