我的代码是这样的
ifstream myfile;
string fileName;
cin >> filename;
myfile.open(fileName);
我收到了一条相当冗长的错误消息,并且无法弄清楚如何将其通过管道传输到一个文件(我尝试了几件事,但我认为我可能没有权限,因为我在学校的远程终端上),所以我截图了。
抱歉,如果这是禁忌,但这是我能想到的最快的事情。它引用的行(main.cpp 22)是行
myfile.open(fileName);
同样,可以在 Visual Studio 2013 中完美编译和运行,但不能在此 linux shell 中运行。老实说,如果有人能帮助我理解错误消息,那将是一个开始。
在此先感谢您的帮助
最佳答案
您需要使用编译器标志 -std=c++11
。以下程序在我的机器上编译和构建良好,使用:
g++ -Wall -std=c++11 test-484.cc -o test-484
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream myfile;
string fileName;
cin >> fileName;
myfile.open(fileName);
return 0;
}
顺便说一句,在您发布的代码中,您有
string filename;
^^ lower case n not upper case N
关于c++ - 打开文件流时在 unix 终端中生成编译器错误,但在 visual studio 2013 中不生成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27833779/