Complement: Play file 1-count the number of characters in a text file

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.