C++学习(38)
1 //用getline成员函数读取文件的内容 2 #include<fstream.h> 3 int main(){ 4 ifstream ifs("Data.dat"); 5 char buffer[80]; 6 int n=0; 7 8 while(!ifs.eof()){ 9 ifs.getline(buffer,sizeof(buffer)); 10 cout<<buffer<<endl; 11 n++; 12 } 13 cout<<"字符行数为:"<<n<<endl; 14 ifs.close(); 15 return 0; 16 }
Data.dat的文件内容为
1 sadf 2 asdfff 3 cxx 4 x

posted on 2018-07-01 18:35 孙悟空son_ku_kong 阅读(102) 评论(0) 收藏 举报
浙公网安备 33010602011771号