33,321
社区成员




/*
Display a file a line at a time, waiting for the user to press
the "Enter" key after each line.
*/
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
int main() {
vector<string> lines;
ifstream in("filename.cpp");
string line;
while(getline(in, line))
lines.push_back(line);
char ch;
for(int i = 0; i < lines.size(); i++) {
cout << lines[i];
cin.get();
cout << endl;
}
}
不知符不符合题意
/*
Display a file a line at a time, waiting for the user to press
the "Enter" key after each line.
*/
#include <iostream>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
int main() {
vector<string> lines;
ifstream in("filename.cpp");
string line;
while(getline(in, line))
lines.push_back(line);
char ch;
for(int i = 0; i < lines.size(); i++) {
cout << lines[i];
//cin.get(); 原来你这样意思是任意字符都可以,题目要求是回车
while(cin.get(ch))//获取一个字符
{
if(ch=='\n') break;//判断是否是回车
}
//cout << endl;
}
}