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

前端 未结 9 1642
灰色年华
灰色年华 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:53

    You can cast the constant. For example:

    min(static_cast(9), example2);
    

    You can also use the constructor syntax:

    typedef unsigned char uchar;
    min(uchar(9), example2);
    

    The typedef isn't required on all compilers.

提交回复
热议问题