I was wondering if there is a way to output the hexdump or raw data of a file to txt file. for example I have a file let's say "data.jpg" (the file type is irrelevant) how can I export the HEXdump (14ed 5602 etc) to a file "output.txt"? also how I can I specify the format of the output for example, Unicode or UTF? in C++
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
- What is the correct way to declare and use a FILE
You can use a loop, fread and fprintf: With read you get the byte-value of the bytes, then with fprintf you can use the
%x
to print hexadecimal to a file.If you want this to be fast you load whole machine-words (int or long long) instead of single bytes, if you want this to be even faster you fread a whole array, then sprintf a whole array, then fprintf that array to the file.
This is pretty old -- if you want Unicode, you'll have to add that yourself.
Maybe something like this?
You just have to replace
buffer
with anifstream
that reads the binary file, and write the output to a textfile using anofstream
instead ofcout
.