Is there a function that returns the ASCII value of a character? (C++)

前端 未结 5 1137
生来不讨喜
生来不讨喜 2020-12-31 05:14

I need a function that returns the ASCII value of a character, including spaces, tabs, newlines, etc...

On a similar note, what is the function that converts between

5条回答
  •  没有蜡笔的小新
    2020-12-31 05:46

    You may be confusing internal representation with output. To see what value a character has:

    char c = 'A';
    cout << c << " has code " << int(c) << endl;
    

    Similarly fo hex valuwes - all numbers are hexadecimal numbers, so it's just a question of output:

    int n = 42;
    cout << n << " in hex is " << hex << n << endl;
    

    The "hex" in the output statement is a C++ manipulator. There are manipulators for hex and decimal (dec), but unfortunately not for binary.

提交回复
热议问题