Read A Text File
Date : July 21, 2004
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; } }
Tags:
C++