c++ - 无法使用文件处理创建和打开文件
问题描述
我正在编写基本代码,但在尝试打开文件时遇到错误。我经历了一次艰难的休息,不得不从基础开始。以下是我遇到错误的代码部分:
int main()
{
string name;
fstream file;
cout << " Enter file name and type (E.g filname.txt) : ";
cin >> name;
file.open(name);
以下是错误:
[错误] 没有匹配函数调用 'std::basic_fstream<char>::open(std::string&)'
经过长时间的休息后,我将返回,因此对于任何不一致之处,我深表歉意。
解决方案
如果std::basic_fstream::open(std::string&)
重载不可用,您可能正在使用 C++11 之前的某些 C++ 版本进行编译。
确保您至少使用 C++11 进行编译,它应该没问题。