Files
BasicsOfComputerSoftwareEng…/OOP/13Exam/2.4.cpp
2023-06-02 00:03:58 +08:00

27 lines
519 B
C++
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// 已知文件test.txt的内容如下
// Good Morning!
// Good Night!
// Good Luck!
// 补充下面程序,使得输出结果如下:
// 1:Good Morning!
// 2:Good Night!
// 3:Good Luck!
#include <iostream>
#include <fstream>
using namespace std;
const int size = 100;
int main() {
char buf[::size];
// _______________
ifstream in("test.txt", ios::in);
int i = 1;
while (in.getline(buf, ::size)) {
// ____________________
cout << i <<":" << buf << endl;
i++;
}
}