1// reading a text file
2#include <iostream>
3#include <fstream>
4#include <string>
5using namespace std;
6
7int main () {
8 string line;
9 ifstream myfile ("example.txt");
10 if (myfile.is_open())
11 {
12 while ( getline (myfile,line) )
13 {
14 //use line here
15 }
16 myfile.close();
17 }
18
19 else cout << "Unable to open file";
20
21 return 0;
22}
1#include<iostream>
2#include<fstream>
3
4using namespace std;
5
6int main() {
7
8 ifstream myReadFile;
9 myReadFile.open("text.txt");
10 char output[100];
11 if (myReadFile.is_open()) {
12 while (!myReadFile.eof()) {
13
14
15 myReadFile >> output;
16 cout<<output;
17
18
19 }
20}
21myReadFile.close();
22return 0;
23}
24
25