永发信息网

C++如何统计一个文件有多少行字符

答案:3  悬赏:0  手机版
解决时间 2021-03-10 00:06
  • 提问者网友:风月客
  • 2021-03-09 05:24
C++如何统计一个文件有多少行字符
最佳答案
  • 五星知识达人网友:独钓一江月
  • 2021-03-09 06:09
#include<cstdlib>
#include<fstream>
using namespace std;
int main(int argc,char *argv[])
{
const int N=1024;
const char f[]="in.txt";
int line=0;
char buf[N];

ifstream inf(f,ios_base::in);

while(inf.getline(buf,N))
{
line++;
}
inf.close();
printf("文件%s共有%d行!\n",f,line);
system("PAUSE");
return EXIT_SUCCESS;
}
全部回答
  • 1楼网友:佘樂
  • 2021-03-09 08:07
多少行? 还是字节数?
  • 2楼网友:忘川信使
  • 2021-03-09 07:40
#include #include using namespace std; int main() {     fstream f("test.txt",ios::in);     char c; int n=0;     while(f.get(c))n++; cout<
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯