How to read a file without doing any operation on it. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to read a file without doing any operation on it.

I just want to read a file and print it on the screen.

8th Mar 2018, 7:08 PM
Praveen Soni
Praveen Soni - avatar
2 Answers
+ 3
Without doing any operation on it? I'm not sure that's possible. Even double-clicking on a file to open it and read it via the OS is still an operation. http://www.cplusplus.com/doc/tutorial/files/ // reading a text file #include <iostream> #include <fstream> #include <string> using namespace std; int main () { string line; ifstream myfile ("example.txt"); if (myfile.is_open()) { while ( getline (myfile,line) ) { cout << line << '\n'; } myfile.close(); } else cout << "Unable to open file"; return 0; }
8th Mar 2018, 7:35 PM
Fata1 Err0r
Fata1 Err0r - avatar
0
Not changing is best achieved with an ifstream.
8th Mar 2018, 8:22 PM
Timon Paßlick