Need help for a program that opens a file .txt and than it copy the text in a string. | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 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?

3rd Jun 2017, 12:19 PM
Umbe
Umbe - avatar
2 Antworten
+ 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; }
3rd Jun 2017, 12:59 PM
Jobelle
Jobelle - avatar
+ 6
thanks a lot Jobelle
3rd Jun 2017, 1:12 PM
Umbe
Umbe - avatar