Opening a file and getting the HEX values

I want to open a file and get the first 70 HEX values and put them in an array. I am using MS VC++.

I would be greatful for any help!!
Thanks,

Malc0lm

Comments

  • : I want to open a file and get the first 70 HEX values and put them in an array. I am using MS VC++.
    :
    : I would be greatful for any help!!
    : Thanks,
    :
    : Malc0lm
    :

    I'm assuming you mean a file with the format:

    A5 76 DEADBEEF etc...

    or something to that effect. If you mean get the BINARY values (eg 'a' = 41h) that's something totally different and has nothing to do with hexadecimal (you may have gotten that idea from hex editors).

    Anyways, assuming the first case, then you can use the following standard C++ code.

    [code]
    #include

    using namespace std;

    int main(){
    int array[70];
    cin.setf(ios_base::hex,ios_base::basefield);
    for(int i=0;i<70;i++){
    cin>>array[i];
    }
    }
    [/code]

    A few notes about this code:
    a) You can use manipulators if you prefer, there just wasn't much point in this case.
    b) Uh, you may have noticed that I'm taking the value from the stdin. This isn't really a problem for your purposes running the program as:

    theprogram if that floats your boat. I didn't want to include an extra header for functionality I wouldn't need.
    d) I'm pretty sure that this code is syntactically correct, and I'm pretty sure that it's all 100% standard C++, SO if your compiler chokes on it get a better compiler. I don't know how good MSVC++ is on standard compliance, which is bad considering I have MSVC++... of course, I always use Borland.

    "We can't do nothing and think someone else will make it right."
    -Kyoto Now, Bad Religion

Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion