+ 5
Need help for a program that opens a file .txt and than it copy the text in a string.
The best thing you can do is to show me an example but an advice is appreciated too. Edit: could a program opens a file which is wrote from the user in the input? Can you help me?
2 Réponses
+ 21
Reading from file:
// file.txt:
// hello world
#include <iostream>
#include <fstream>
using namespace std;
int main() {
fstream file("file.txt");
string str;
getline(file, str);
cout<<str; //prints "hello world";
return 0;
}
+ 6
thanks a lot Jobelle