[cfe-dev] uint8_t not getting output to cout?

Bruce Hoult via cfe-dev cfe-dev at lists.llvm.org
Tue Feb 12 20:15:47 PST 2019


Presumably, on your system, uint8_t is typef'd to "char".

Try changing the 2 to 65 and see if you get 'A'. And if you change the
13 to 10 you'll get a newline after the 2nd '-'.

On Tue, Feb 12, 2019 at 8:12 PM Shriramana Sharma via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
>
> Hello. Please see the following simple code:
>
> #include <cstdint>
> #include <cstdio>
> #include <iostream>
> int main()
> {
>     std::uint16_t y = 2019;
>     std::uint8_t m = 2, d = 13;
>     std::printf("%d-%d-%d\n", y, m, d);
>     std::cout << y << '-' << m << '-' << d << std::endl;
>     std::cout << int(y) << '-' << int(m) << '-' << int(d) << std::endl;
> }
>
> The above code outputs:
>
> 2019-2-13
> 2019- -
> 2019-2-13
>
> The character on the second line after the hyphen is Unicode codepoint 0x0002!
>
> The same behaviour happens with both Clang 6 and GCC 7.3.0 available
> by default on my Kubuntu Bionic LTS system.
>
> What is wrong with expecting std::cout to properly print uint8_t when
> printf can do it?
>
> --
> Shriramana Sharma ஶ்ரீரமணஶர்மா श्रीरमणशर्मा 𑀰𑁆𑀭𑀻𑀭𑀫𑀡𑀰𑀭𑁆𑀫𑀸
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list