Note that there are some explanatory texts on larger screens.

plurals
  1. PO(C++) Trouble writing hex to .dat file
    primarykey
    data
    text
    <p>My program is pretty long and complex so I cannot explain it all, I will try to just explain my current situation, however.</p> <p>I have a .dat file (729 of them but only 1 for this example) and I need to overwrite THE WHOLE FILE (even if my new data is smaller than the current data) with a couple strings containing hex values. </p> <p>Here is a snippet from my program:</p> <pre><code>ofstream xbox_final(xboxit-&gt;c_str(), ios::binary); //other stuff xbox_final.write("0a00000a00054c6576656c070006426c6f636b7300008000", 48); xbox_final.write(new_bytes, new_bytes.length()); xbox_final.write(xboxbytes, xboxbytes.length()); xbox_final.close(); </code></pre> <p>"xboxit->c_str()" in the ofstream is there because I'm inputting and outputting a BUNCH of files from a file list and this was necessary but gives me no errors, if that makes sense.</p> <p>The strings "new_bytes" and "xboxbytes" contains hex values (000007000a0445 etc...)</p> <p>For now my program has just been writing to a text document. I need it to write that hex data in that order to the .dat file.</p> <p>I did some searching around and this fixes the const char problem:</p> <pre><code>//other stuff string header("0a00000a00054c6576656c070006426c6f636b7300008000"); WriteStr2BinFh( header, xbox_final); WriteStr2BinFh( new_bytes, xbox_final); WriteStr2BinFh( xboxbytes, xbox_final); //other stuff void WriteStr2BinFh( const std::string&amp; St, std::ostream &amp;out ) { out.write( St.c_str(), St.size() ); } </code></pre> <p>Creating new .dat files somewhere else is also an acceptable option.</p> <p>I JUST CAN'T WRITE THE HEX VALUES, THEY ALWAYS SHOW UP AS TEXT IN THE DAT FILE.</p> <p>Any help would be appreciated :)</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload