【发布时间】:2017-02-03 13:57:28
【问题描述】:
我正在尝试制作一个可以根据用户输入打开文件的程序。 这是我的代码:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string filename;
ifstream fileC;
cout<<"which file do you want to open?";
cin>>filename;
fileC.open(filename);
fileC<<"lalala";
fileC.close;
return 0;
}
但是当我编译它时,它给了我这个错误:
[Error] no match for 'operator<<' (operand types are 'std::ifstream {aka std::basic_ifstream<char>}' and 'const char [7]')
有谁知道如何解决这个问题? 谢谢...
【问题讨论】:
-
查看
std::ifstream的文档。 -
... 并改用
std::ofstream。
标签: c++ file io user-input