i'm new with c++, i want to write a function to open multiple file with same extension in folder, and i write a code like this:
string get_folder(string path, string ext, string folder, string list_name)
{
//Set đường dẫn hiện tại
auto c_path = filesystem::current_path();
stringstream set_path;
set_path << c_path;
string cur_path;
set_path >> cur_path;
cur_path.erase(cur_path.begin(),cur_path.begin()+1);
cur_path.erase(cur_path.end()-1,cur_path.end());
cur_path = cur_path + "\\";
path = cur_path + path;
folder = cur_path + folder;
//List các file
cout << "Đang lấy danh sách file\n";
ofstream list_file(list_name);
int counter;
for (auto &p : filesystem::recursive_directory_iterator(path)){
if (p.path().extension() == ext)
list_file << p.path().parent_path().stem().string() << "/" << p.path().stem().string() << ext << '\n';
counter++;
}
list_file.close();
//Tạo thư mục xuất
filesystem::create_directories(folder);
//Lấy danh sách file
ifstream get_list(list_name);
string file_list, file_name[counter];
int i;
for (i = 1; i < counter; i++){
while(getline(get_list, file_list)){
if (file_list.find(ext) != file_list.npos)
file_name[i] = file_list;
return file_name[i];
break;
}
}
get_list.close();
}
but when i tried to call it from main()
, it can't return multiple file name like i want, so how could i make this function return multiple file_name[i]
to the main()
function?