更新时间:2023-02-07 11:24:52
//Open a file
//you first operation generally performed on an object of one of these classes is to associate it to a real file
//text file streams are those where the ios::binary flag is not included in their opening mode.
// and then writing on a text file
#include <iostream>
#include <fstream>
using namespace std;
int main () {
string line;
ifstream myfile ("read.txt");
ofstream writefile;
if (myfile.is_open())
{
writefile.open ("write.txt");
while ( getline (myfile,line) )
{
cout << line << '\n';
writefile << line << '\n';
}
writefile.close();
myfile.close();
}
else cout << "Unable to open file";
return 0;
}