0

I have a file with hex numbers as follows:

00042980 
00020000 
00020000 
00028000 
00020008 
00021000 
01028000 
00000000 
00000000 

In this same exact fashion.
How do I read this file in binary in C++?

0

1 Answer 1

7

You can use the std::hex manipulator:

#include <fstream>
#include <iostream>

using std::cout;
using std::hex;
using std::ifstream;

int main() {
    ifstream input("file");
    int data;
    while(input >> hex >> data) {
        cout << data << std::endl;
    }
}
2
  • 3
    Be sure to select this as the best answer if you find the solution effective.
    – user865927
    Commented Mar 10, 2012 at 20:51
  • 1
    +1 for all-around good C++ practice (proper using directives, safe I/O loop, etc.)! Commented Mar 10, 2012 at 20:57

Not the answer you're looking for? Browse other questions tagged or ask your own question.