uint8_t can't be printed with cout

前端 未结 8 2154

I have a weird problem about working with integers in C++.

I wrote a simple program that sets a value to a variable and then prints it, but it is not working as expe

8条回答
  •  既然无缘
    2020-11-21 14:03

    The operator<<() overload between istream and char is a non-member function. You can explicitly use the member function to treat a char (or a uint8_t) as an int.

    #include 
    #include 
    
    int main()
    {
       uint8_t aa=5;
    
       std::cout << "value is ";
       std::cout.operator<<(aa);
       std::cout << std::endl;
    
       return 0;
    }
    

    Output:

    value is 5
    

提交回复
热议问题