简答题
C++
题号 #2657831
编写一程序,将C++源程序每行前加上行号与一个空格。
参考答案
暂无
答案解析
#include<iostream>
#include<fstream>
using namespace std;
int main(){
int i=1;
char c[1000];
ifstream ifile("D:\\10_4_3.cpp");
ofstream ofile("D:\\r10_4_3.cpp");
while(!ifile.eof()){
ofile<<i++<<": ";
ifile.getline(c,999);
ofile<<c<<endl;
}
ifile.close();
ofile.close();
return 0;
}
#include<fstream>
using namespace std;
int main(){
int i=1;
char c[1000];
ifstream ifile("D:\\10_4_3.cpp");
ofstream ofile("D:\\r10_4_3.cpp");
while(!ifile.eof()){
ofile<<i++<<": ";
ifile.getline(c,999);
ofile<<c<<endl;
}
ifile.close();
ofile.close();
return 0;
}