我在显示此文件时出现问题。我正在尝试创建一个文件并将其显示在输出屏幕中。但getline不起作用。它不断给我一个“40号线未声明”的提示。我尝试了一些事情,没有做任何事情。问题是什么?阅读和显示文件
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <string>
using namespace std;
int main()
{
char filename[] = "Hello.txt";
string line = "Hello, this is my output file";
ofstream OutFile;
OutFile.open(filename);
if(OutFile.fail()) // check for successfully open ,
{
cout << "file named can not be found \n";
exit(1);
}
OutFile << line;
if (OutFile.is_open())
OutFile.getline(line);
OutFile.close();
system("pause");
}
我已经试过,它不起作用,或者 – jon 2014-11-04 22:12:38
“不工作”是非常含糊。你得到了什么错误? – 0x499602D2 2014-11-04 22:13:00