我试图将多个文件的内容添加到另一个文件,但我遇到了麻烦.似乎每次添加一个文件的内容时,它都会覆盖我添加的最后一个文件的内容.这是我的代码:
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++;
}
Run Code Online (Sandbox Code Playgroud)
一如既往,我感谢任何帮助!
您必须使用ios::app"附加"模式配置文件流.
using namespace std;
ofstream foo ("foo.bin", ios::out | ios::app | ios::binary);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
822 次 |
| 最近记录: |