Code Library
Home Submit Free Hosting Link To Us Contacts

CPP Read from File

CPP Read from File CPP CPP Read from File Download (.zip)



#include <iostream>
#include <fstream.h>

int main() {
        char inLine[128];
        char fname[24];
        ifstream inFile;

        cout << "Enter the name of the file: ";
        cin >> fname;

        /* open the file */
        inFile.open(fname, ios::in);

        /* if opening didn't fail */
        if(!inFile.fail()) {

                while(!inFile.eof()) {
                        inFile >> inLine;
                        cout << inLine << endl;
                }
                
                inFile.close();
        } else 
                cout << "Error Opening File.";

        return 0;
}




  • CPPCreating and writing files Output to File Read from File


Tatet