代码:
#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;
}