I am making a program that writes a predefined line to a file at startup. The file size is about 5 mb, so filling in a string of 5 mb of data in hexadecimal is a big variable. When I try to compile it, I get an error when the string is too large. Is 5mb really that? I split the line into 4 sections, but each section is still too large.: / What can I quickly and easily do to fix this situation.
Note: I consider myself a novice programmer, so try not to go too far above your head: P
An example of how I write a line to a file:
string file_hex("huge_a**_string_goes_here_or_in_separate_cpp"); ofstream file_out; file_out.open("tools\\c.exe", ios::binary | ios::trunc); string res; res.reserve(file_hex.size() / 2); for (int i = 0; i < file_hex.size(); i += 2) { std::istringstream iss(file_hex.substr(i, 2)); int temp; iss >> std::hex >> temp; res += static_cast<char>(temp); } file_out << res; file_out.close();
source share