6,10 统计字节

来源:互联网 发布:程序员找男朋友 编辑:程序博客网 时间:2024/06/05 08:30

下面程序的功能是统计文本文件abc.txt中的字符个数,请填空将程序补充完整。

 

#include <iostream>
#include <cstdlib>
#include <fstream>
using namespace std;
int main()
{
    fstream file;
    file.open("abc.txt", ios::in);
    if(!file)
    {
        cout<<"abc.txt can¡¯t open."<<endl;
        exit(1);
    }
    char ch;
    int i=0;
    while( !file.eof())
    {
        file.get(ch);
        ++i ;
    }
    cout<<"Character: "<<i<<endl;
    file.close();
     return 0;
}

 

 

 

0 0
原创粉丝点击