| | |
Problem with writing hex values
Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved |
•
•
Join Date: Nov 2008
Posts: 8
Reputation:
Solved Threads: 0
Hi everyone,
i wrote this small app and it works fine but it erases everything up to the offset and everything after it.
Anyone knows how to avoid that?
regards
i wrote this small app and it works fine but it erases everything up to the offset and everything after it.
Anyone knows how to avoid that?
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> int main() { int hex = 0x75; std::ofstream f("sample.exe", std::ios::binary); f.seekp(1169, std::ios::beg); f.write(reinterpret_cast<const char *>(&hex), 2); f.close(); return 0; }
regards
also use mode std::ios::ate (AT End)
The default mode for ofstream opening is std::ios::trunc, (TRUNCate), which deletes any previous content of the file. ios::ate preserves the file, allows you to move the file pointer anywhere within the current content.
The default mode for ofstream opening is std::ios::trunc, (TRUNCate), which deletes any previous content of the file. ios::ate preserves the file, allows you to move the file pointer anywhere within the current content.
Everyone's gotta believe in something. I believe I'll have another drink.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
~~~~~~~~~~~~~~~~~~
Looking for an exciting graduate degree? Robotics and Intelligent Autonomous Systems (RIAS) at SDSM&T See the program brochure here.
•
•
Join Date: Nov 2008
Posts: 8
Reputation:
Solved Threads: 0
It still doesn't work using this code.
It produces the same error again.
It produces the same error again.
C++ Syntax (Toggle Plain Text)
#include <iostream> #include <fstream> int main() { int hex = 0x75; std::ofstream f("sample.exe", std::ios::binary | std::ios::ate); f.seekp(1169, std::ios::beg); f.write(reinterpret_cast<const char *>(&hex), 2); f.close(); return 0; }
![]() |
Similar Threads
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
- File Format Conversion/Compression (C)
- Lite-On CD Burner problem (Storage)
- I've got Trojan.Holax... is this bad? (Viruses, Spyware and other Nasties)
- not-a-virusadware (Viruses, Spyware and other Nasties)
Other Threads in the C++ Forum
- Previous Thread: Standard Output Error: Forking to Obtain Prime Numbers
- Next Thread: Need help in a program
| Thread Tools | Search this Thread |
api application array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp iamthwee ifstream input int java lib library linkedlist linker list loop looping loops map math matrix memory newbie news number numbertoword output pointer problem program programming project python random read recursion recursive reference rpg simple sorting string strings studio temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






