(1)下面程序的功能是统计文本文件abc.txt中的字符个数,请填空将程序补充完整。
#include <iostream>
#include <cstdlib>
#include <fstream>// (1)
using namespace std;
int main()
{
fstream file;
file.open("abc.txt",ios::out); // (2)
if(!file)
{
cout<<"abc.txt can’t open."<<endl;
exit(1);
}
char ch;
int i=0;
while(!file.eof()) // (3)
{
file.get(ch);
++i; // (4)
}
cout<<"Character: "<<i<<endl;
file.close();// (5)
return 0;
}
心得:
其实有个纠结的地方。。。刚开始要打开文件时是要ios::out还是ios::in啊?都试了试完全没区别啊
图片: