viewing paste readfile | C++

Posted on the | Last edited on
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
#include <iostream>
#include <fstream>
#include <cstdlib>
 
using namespace std;
int main () {
    
    fstream myfile;
    
    myfile.open("testfile.txt");
    
    if(myfile.fail()){
        cout << "Unable to locate testfile.txt" << endl;
        exit(0);
    }
    
    while(myfile.good()){
        
        string str;
 
        myfile >> str;
        
        cout << str << endl;
        
    }
    
    return 0;
}
 
Viewed 1326 times, submitted by Streusel.