File Handling Read file in notepad


Home || News || Stories || Installer ||

 

File I/O: 

Create a file in notepad and name it samplecpp and inside it write the details n the output.

Read

#include <iostream>
#include <string>
#include <fstream> // Input or read/output or Write stream class to operate on files

using namespace std;

ifstream inFile; // "input file stream" variable infile for reading files
string str;
int number;
char letter;

int main()
{
    inFile.open("samplecpp.txt");
    if (inFile.fail())
        cout << endl << "File not found!" << endl;
    else
    {
        while (!inFile.eof()) // eof "end of file"
        {
            getline(inFile, str);
            cout << str << endl;
        }
        inFile.close();
    }
    return (0);
}


OUTPUT



Mga Komento