Helpful Information
 
 
Category: Computer Programming
c++

Hi
i want to make a small program that read and write to a file, so i want to know the commands that used to read and write to a file.
with many thanks

#include <iostream.h>
#include <fstream.h>

int main() {
ifstream myInput("somefile.txt");
char inp;
while (myInput >> inp) {
cout << inp;
}

return 0;
}

For example. ifstream objects also have a few other methods, such as readline().

Writing to a file is easy:

ofstream output("myoutput.txt");
output << "hello world!";

writes "hello world!" to myoutput.txt

thank you very much :)










privacy (GDPR)