如何从文件中读取并将其附加到C 中另一个文件的末尾

how to read from a file and append it to the end of another file in c++

本文关键字:文件 另一个 读取      更新时间:2023-10-16

我打开了两个文件,我想找到最有效的方法,将数据从文件中放置到填充中。我尝试了rdbuf(),但它不起作用,而外档则是相同的,因此我需要对rdbuf()有更多解释,并且还有另一种方法将文件附加到另一个吗?

ofstream writeto;
writeto.open(srr.c_str(),ios::app);
cout<<"give me the file you want to copy from  : ";
string written;
cin>>written;
ifstream writefrom;
writefrom.open(written.c_str());

假设您要复制整个输入文件:

writeto << writefrom.rdbuf();

另外,您应该使用std::getline()代替operator>>,以便在其中包含空格字符的文件路径/名称:

getline(cin, written);

将文件读取到流对象中,将下一个文件读取到流中。写出流。

相关文章: