I have a folder filled with hundreds of .aac files, and I'm trying to "pack" them into one file in the most efficient way that I can.
I have tried the following, but only end up with a file that's only a few bytes long or audio that sounds warbled and distorted heavily.
// Now we want to get all of the files in the folder and then repack them into an aac file as fast as possible
void Repacker(string FileName)
{
    string data;
    boost::filesystem::path p = "./tmp/";
    boost::filesystem::ofstream aacwriter;
    aacwriter.open("./" + FileName + ".aac", ios::app);
    boost::filesystem::ifstream aacReader;
    boost::filesystem::directory_iterator it{ p };
    cout << "Repacking File!" << endl;
    while (it != boost::filesystem::directory_iterator{}) {
        aacReader.open(*it, std::ios::in | ios::binary);
        cout << "Writing " << *it << endl;
        aacReader >> data;
        ++it;
        aacwriter << data;
        aacReader.close();
    }
    aacwriter.close();
}
I have looked at the following questions to try and help solve this issue
Merge multiple txt files into one
How do I read an entire file into a std::string in C++?
Read whole ASCII file into C++ std::string
However unfortunately, none of these answer my question.
They all either have to do with text files, or functions that don't deal with hundreds of files at once.
I am trying to write Binary data, not text. The audio is either all warbled or the file is only a few bytes long.
If there's a memory efficent method to do this, please let me know. I am using C++ 20 and boost. Thank you.
 
     
    