How do I specify an integer literal of type unsigned char in C++?

前端 未结 9 1636
灰色年华
灰色年华 2020-12-08 18:38

I can specify an integer literal of type unsigned long as follows:

const unsigned long example = 9UL;

How do I do likewise for an unsigned

相关标签:
9条回答
  • 2020-12-08 18:59

    The question was how to "specify an integer 'literal' of type unsigned char in C++?". Not how to declare an identifier.

    You use the escape backslash and octal digits in apostrophes. (eg. '\177')

    The octal value is always taken to be unsigned.

    0 讨论(0)
  • 2020-12-08 19:04

    I suppose '\0' would be a char literal with the value 0, but I don't see the point either.

    0 讨论(0)
  • 2020-12-08 19:09

    Assuming that you are using std::min what you actually should do is explicitly specify what type min should be using as such

    unsigned char example2 = 0;
    min<unsigned char>(9, example2);
    
    0 讨论(0)
提交回复
热议问题