I have a info_list variable of type std::list<std::pair<std::size_t, std::byte*>> that I want to iterate and save data in binary format sequentially into a file. Here is what I tried:
void write_data() {
std::basic_ofstream<std::byte> file("data.bin", std::ios::binary);
for (decltype(auto) info : info_list) {
file.write(info.second, info.first);
}
}
The first of the std::pair is the size of the data that second pointer points to.
I'm not good with these C++ streams. The file is being saved empty. What am I doing wrong?
I'd like to avoid using C features to achieve this.
EDIT:
I tried using std::ofstream instead of std::basic_ofstream<std::byte> and it worked... Why std::basic_ofstream<std::byte> is not working here? Am I missing something?