I need to read 16 bits from the binary file as std::string or char *. For example, a binary file contains 89 ab cd ef, and I want to be able to extract them as std::strings or char *. I have tried the following code:
ifstream *p = new ifstream();
char *buffer;
p->seekg(address, ios::beg);
buffer = new char[16];
memset(buffer, 0, 16);
p->read(buffer, 16);
When I try to std::cout the buffer, nothing appeared. How can I read these characters in the binary file?
EDIT: I was looking for the buffer to be a int type such as "0x89abcdef". Is it possible to achieve?
addresswhen this code executes?*pon the stack:ifstream p("somefile.txt");"89 ab cd ef")?strings bin_file_pathto get a list of all the strings from a binary fileifstream::readfails to read as many bytes as you asked for it sets some flags on the stream object which you can check withifstream::failandifstream::eof.