gpt4 book ai didi

c++ - 在C++中读写多个文件

转载 作者:行者123 更新时间:2023-11-28 02:06:31 24 4
gpt4 key购买 nike

<分区>

我想从用户那里获取多个文件地址,然后将它们作为二进制模式读写到一个struct.txt文件中,并从struct.txt文件中导出到其他程序中。请指导我。 Importing - merge exporting - unmerge

#include <iostream>
#include <string>
#include <fstream>
#include <iterator>
#include <algorithm>
using namespace std;
int tedad_file=0; // get count of files from user //

int main()
{
int tr=0;
cout << "please enter count of files you want to merge ";
cin >> tedad_file;
cout << "\n";
std::string *files[tedad_file];
int counter=0;
int temp=0;
for(;temp<tedad_file;temp++) // getting file's address from user and add them into arrays of string (files variable)
{
cout << "Lotfan address file " << temp + 1 << " vared konid: \n";
cin >> *files[temp];
}

std::ofstream output_file( "D:\\struct.txt", std::ios::binary ) ;
int x=0;
for(;x<tedad_file;x++) // for - read content of files to merge them into struct.txt ---- for example tedad_file is 3
{
std::ifstream first_file((char *)&files[tedad_file], std::ios::binary ) ;
output_file << first_file.rdbuf();
}
return 0;
}

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