I'm reading a file in binary mode with std::ifstream
. Here is the way I'm reading from the file:
enum class Resources : uint64_t
{
Resource_1 = 0xA97082C73B2BC4BB,
Resource_2 = 0xB89A596B420BB2E2,
};
struct ResourceHeader
{
Resources hash;
uint32_t size;
};
int main()
{
std::ifstream input(path, std::ios::binary);
while (true)
{
if (input.eof()) break;
ResourceHeader RCHeader{};
input.read((char*)&RCHeader, sizeof(ResourceHeader));
uint16_t length = 0;
input.read((char*)&length, sizeof(uint16_t));
std::string str;
str.resize(length);
input.read(&str[0], length); /* here I get a string from binary file */
/* and some other reading */
}
}
After reading, I want to make some changes in some data that I read from the file, and after all changes then write the changed data in a new file.
So I want to know, how can I store the edited char into a buffer (BTW, I don't know the exact size of the buffer with edits)? Also, I need to be able to go back and forth in new created buffer and edit some data again.
So, how can I achieve this?