我在顯示此文件時出現問題。我正在嘗試創建一個文件並將其顯示在輸出屏幕中。但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