如何编译一个c++程序 一次显示文件的一行 等待用户按回车键后显示下一行

来源:百度知道 编辑:UC知道 时间:2024/07/02 16:57:59

#include<iostream>
#include<fstream>
#include<string>
#include<vector>
using namespace std;
int main()
{
vector<string> v;
ifstream in("exercise7.cpp");
string line;
char ch;
while(getline(in,line))
v.push_back(line);
cout<<"Press enter key to continue...";
for(int i=0;i<v.size();i++)
{
ch=getchar();
if(ch=='\n')
{ cout<<i<<" : "<<v[i]<<endl;
cout<<"Press enter key to continue... ";
}
else
{
cout<<endl<<"error!"<<endl;
i--;
ch=getchar();
}
}
return 0;
}