+ 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.
2 Réponses
+ 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;
}
0
Not changing is best achieved with an ifstream.