Week 14th (small play file)

Source: Internet
Author: User

*/
Copyright (c) 2015, College of Computer Science, Yantai University
*all rights reserved.
* File name: Week 14th (small play file)

* Wangzhong
* Completion Date: 2015.6.09

Version number: v1.0
*
* Problem Description: The function of the following program is to add the text file Abc.txt all lines in the line number after the write to the Newabc.txt file, please fill in the blanks to complete the program.

* Input Description:

* Program output:

#include <iostream> #include <cstdlib> #include <fstream>using namespace Std;int main () {    fstream Outfile,infile;    Infile.open ("Abc.txt", ios::in); (1)    if (!infile) {        cout<< "Can ' t open the file." <<endl;        Abort ();    }    Outfile.open ("Newabc.txt", ios::out);//(2)    if (!outfile) {        cout<< "Can ' t open the file." <<endl;        Abort ();    }    Char buf[80];    int i=1;    while (!infile.eof ())//(3)    {        infile.getline (buf,80);//(4)        outfile<<i++<< ":" << buf<<endl; (5)    }    infile.close ();    Outfile.close ();    return 0;}

The same code, using two different files, ran out of two completely different results, asking the great God why this

Week 14th (small play 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.