stream类流文件的操作

it2024-05-13  49

#include<iostream> #include<fstream> #include<string> using namespace std; ifstream fin ("d:/test1.txt"); ofstream fout("d:/test2.txt"); int main() { string str,res; while (fin >> str) res += str+'\n'; fout << res << endl; return 0; }

Run

test1: 

abc defg hijk pqr

test2:

abc

defg

hijk

pqr 

最新回复(0)