language: C++ 4.7.2 (gcc-4.7.2)
date: 708 days 3 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#include<iostream>
#include<cstdlib>
#include <fstream>
 
using namespace std;
 
// Associate stream objects with external file names
 
#define inFile "InData.txt" // directory name for file we copy from
#define outFile "OutData.txt"   // directory name for file we copy to
 
int main(){
    int lineCount;
    string line;
    ifstream ins;   // initialize input object an object
    ofstream outs;  // initialize output object
    // open input and output file else, exit with error
 
    ins.open("inFile.txt");
    if(ins.fail()){
        cerr << "*** ERROR: Cannot open file " << inFile
            << " for input."<<endl;
        return EXIT_FAILURE; // failure return
    }
 
    outs.open("outFile.txt");
    if(outs.fail()){
        cerr << "*** ERROR: Cannot open file " << outFile
            << " for input."<<endl;
        return EXIT_FAILURE; // failure return
    }
 
    // copy everything fron inData to outData
    lineCount=0;
    getline(ins,line);
    while(line.length() !=0){
        lineCount++;
        outs<<line<<endl;
        getline(ins,line);
    }
 
    // display th emessages on the screen
    cout<<"Input file copied to output file."<<endl;
    cout<<lineCount<<"lines copied."<<endl;
 
    ins.close();
    outs.close();
    cin.get();
    return 0;
 
}