Sign in to follow this  
darrylsh

COUTing a BYTE with Dev C++

Recommended Posts

Hi, For the given example below: #include <iostream> using namespace std; int main() { BYTE number; number = 65; cout << number << endl; } MSVC will output 65 as expected (my expectations anyway) while Dev C++ will output 'A' How can I get the first behavior using Dev C++? I don't want to use an int for number because in my real program I perfom some bitwise computations which will be wrong using a 32 bit int but works with an 8 bit BYTE. Thanks, Darryl

Share this post


Link to post
Share on other sites
Still outputs 'A' and not 65. BTW I looked through the headers and found that's the way it is already defined as an unsigned char. I imagine the problem is with iostream cout treating it as a char.

D

Share this post


Link to post
Share on other sites
Quote:
Original post by darrylsh
I imagine the problem is with iostream cout treating it as a char.


Well, DUH! An unsigned char (BYTE is just a typedef, it's not something that exists on its own) is a character. You know, a letter. Cast to unsigned int if you want a numerical value.

cout << static_cast<unsigned int>(number) << endl;

Share this post


Link to post
Share on other sites
I hear what you guys are saying, HOWEVER, using MSVC cout << BYTE outputs the number and not the character and I was hoping to somehow duplicate that behavior without cast. Basically how is MS defining BYTE or cout such that cout << BYTE outputs the value and not the character.

Guess I will just have to do the cast.

darryl

Share this post


Link to post
Share on other sites
Quote:
Original post by darrylsh
I hear what you guys are saying, HOWEVER, using MSVC cout << BYTE outputs the number and not the character and I was hoping to somehow duplicate that behavior without cast.


If so, MSVC's behaviour is incorrect. If you are using VC6, it is not surprising.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this