/*
*Copyright(c)2016,煙臺大學計算機與控制工程學院
*All rights reserved
*文件名稱:123.cpp
*作 者:王蕊
*完成日期:2016年6月14日
*版 本 號:v1.0
*
*問題描述:下面程序的功能是統計文本文件abc.txt中的字符個數,請填空將程序補充完整
*/
#include <iostream>
#include <cstdlib>
#include <fstream> // (1)
using namespace std;
int main()
{
fstream file;
file.open("abc.txt", ios::in); // (2)
if(!file)
{
cout<<"abc.txt can’t open."<<endl;
exit(1);
}
char ch;
int i=0;
while(file.get(ch)) // (3)
{
++i; // (4)
}
cout<<"Character: "<<i<<endl;
file.close();// (5)
return 0;
}
運行結果: