有以下程序: #include<iostream> #include<fstream> using namespace std; int main() { fstream file; file.open("abc.txt", ios :: in); if ( !file ) {cout<<"Can not open abc.txt"<<end1;abort(); } char buf[ 80 ]; int i = 0; while (!file.eof()) {file.getline(buf,80);i++; } cout<<"Lines :"<<i<<end1; file.close(); return 0; } 程序实现的功能是 【15】 。
参考答案:统计文件abc.txt的行数
解析: 函数getline(char*s,streamsize n)从当前输入位置开始提取字符存入s所指向的具有n个字节的字符空间中。程序中这种调用方式是以换行符为结束标志输入字符序列,即输入一行字符(回车换行前的所有字符序列)。程序中通过while循环来统计abc.txt中行数。