C ++ファイルの読み取りと書き込み、追加、上書き、fstreamの使用、getline、書き込みストリーム



C File Read Write



C ++ファイルの読み取りと書き込み、追加、上書き、fstreamの使用
【参考】:c ++ prime(5版)第8章IOライブラリ

#include #include #include using namespace std int main() { //note'/' string fin='D:/cpp/tempvscode/in.txt' string fout='D:/cpp/tempvscode/out.txt' //Two writing methods // ofstream out1(fout,ofstream::app)//Append the end //Write stream ofstream out1(fout)//Overwrite //Read into the stream ifstream in1(fin) //Read a line and store it in s2 string s2 while (getline(in1,s2)) { //Output to file out.txt out1<<s2<<endl } return 0 }