gpt4 book ai didi

c++ - 将多个文件中的信息添加到一个文件中 C++

转载 作者:行者123 更新时间:2023-11-30 00:53:35 25 4
gpt4 key购买 nike

我正在尝试将多个文件的内容添加到另一个文件中,但我遇到了麻烦。好像每次我添加一个文件的内容,它都会覆盖我上次添加的文件的内容。这是我的代码:

  cout << "Enter Directory Location" << endl;
string name;
getline(cin, name);
cout << "Directory: " << name << " Used" << endl;
name += "/title";

int x = 1; // I am assuming that the file number will simply start at 1
int y;
cout << "Enter Number of Files" << endl;
cin >> y;

while(x <= y)
{
stringstream sstm;
sstm << name << x;
name = sstm.str();
name += ".png";
ifstream binfile(name.c_str(),ios::in | ios::binary);

myfile << binfile.rdbuf();
x++;
}

一如既往,我感谢任何帮助!

最佳答案

您必须使用 ios::app 以“追加”模式配置文件流。

using namespace std;
ofstream foo ("foo.bin", ios::out | ios::app | ios::binary);

关于c++ - 将多个文件中的信息添加到一个文件中 C++,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16046063/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com