*/
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)