第十四周项目:小玩文件(1)

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

代码:

#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 be opened."<<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