我正在尝试使用 C++,并在读取文本文件时收到以下错误。知道为什么吗?
输入:
This is a test.
A test, with tabs and too many spaces.
If this is a good one,
then all will be well.
输出:
then all will be well. too many spaces.
代码:
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
int main() {
string line;
ifstream infile ("A5.txt");
if (infile.is_open()) {
while (!infile.eof()) {
getline(infile,line);
cout << line << endl;
}
infile.close();
}
return 0;
}