|
发表于 2020-1-21 20:36:01
|
显示全部楼层
将(ch = getchar()) != EOF 改为
(ch = getchar()) !='\n'
EOF用来读文件,比如读取text.txt文本文件
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
void main(){
ifstream file;
string line;
file.open("text.txt");
int row = 1;
while(!file.eof()){
getline(file,line);
cout << row << " " << line;
row++;
cout<<endl;
}
file.close();
system("pause");
} |
|