laurent
laurent

Reputation: 90756

How to set a character in C++?

This is probably very obvious, in fact so obvious that no C++ reference I could find online cares to document it.

I need to know how to set the byte value of a char in C/C++. For example, if I want the byte value 233 in the char, how do I do?

Upvotes: 1

Views: 2246

Answers (3)

MGZero
MGZero

Reputation: 5963

char x = 233;

Yea, literally as simple as that.

Upvotes: 0

Tim
Tim

Reputation: 4813

A char is a 1byte int. So you can set the value in the same way as you would an int.

char c = 123;
char d = 0x12;

etc...

Upvotes: 3

Bo Persson
Bo Persson

Reputation: 92241

Yes, it is too obvious:

char x = 233;

Upvotes: 6

Related Questions