<span style="font-size:18px;">【项目1 - 小玩文件】
(1)下面程序的功能是统计文本文件abc.txt中的字符个数,</span>
<span style="font-size:18px;">#include <iostream>
#include <cstdlib>
#include <fstream>//
//fstream提供了三个类,用来实现c++对文件的操作。(文件的创建,读写)。
// ifstream -- 从已有的文件读
//
// ofstream -- 向文件写内容
//
// fstream - 打开文件供读写
//
//支持的文件类型
//
//实际上,文件类型可以分为两种: 文本文件和二进制文件.
using namespace std;
int main()
{
fstream file;
file.open("abc.txt", ios::in); // (2)读入文件(在此之前已经创建abc文本文件)
if(!file) {
cout<<"abc.txt can’t open."<<endl;
exit(1);
}
char ch;
int i=0;
while(!file.eof()) // (3)
{
file.get(ch);