Code Library
Home Submit Free Hosting Link To Us Contacts

CPP Output to File

CPP Output to File CPP CPP Output to File Download (.zip)



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

/* for append type = 1
   for normal out type = 0 */

#define type 0

int main() {
        char outLine[50];
        ofstream outFile;
        if(type) outFile.open("out.txt", ios::app);
        else outFile.open("out.txt", ios::out);

        if(!outFile.fail()) {
                cout << "Write text here: ";
                cin >> outLine;

                outFile << outLine << endl;
                outFile.close();
        } else 
                cout << "Error!.";

        return 0;
}




  • CPPCreating and writing files Output to File Read from File


Tatet