Jul
21

Read A Text File

By celso

This will open a text file and read it line by line. As it is, it will just print each line to the screen, so very much like the unix ‘cat’ command, but could very well do anything on the line just read by replacing the cout statement.


#include <fstream>
#include <iostream>
#include <string>

void main() {
    string s;
    ifstream infile;

    infile.open("aaa.txt");

    while(infile >> s) {
        cout << s << endl;
    }
}
Categories : Cpp, Notes

Leave a Comment

You must be logged in to post a comment.