Enter the code:
/* *copyright (c) 2015, *all rights reserved, School of computer and Control engineering, Yantai University. * File name: Sum123.cpp *: Lin Haiyun * Completion Date: August 18, 2015 * version number: v2.0 * Problem Description: Statistical text file abc.txt the number of characters, fill in the blanks to complete the program. * Program input: File read. * Program output: The number of characters in the text file 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.eof ())//(3) { file.get (CH); ++i; (4) } cout<< "Character:" <<i<<endl; File.close ();//(5) return 0;}
Operation Result:
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Complement: Play file 1-count the number of characters in a text file