bitset example

I get this error for the following code:
Error C2398 Element '1': conversion from 'int' to 'unsigned __int64' requires a narrowing conversion 9

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <bitset>

int main()
{
    for (int i; std::cin >> i;)
        std::cout << std::dec << i << " == "
        << std::hex << " 0x " << i << " == "
        << std::bitset < 8 * sizeof(int)>{ i } << '\n';

    system("pause");
    return 0;
}
Last edited on
list-initialisation does not allow implicit narrowing conversions.
https://en.cppreference.com/w/cpp/language/list_initialization#Narrowing_conversions

1
2
        // << std::bitset < 8 * sizeof(int)>{ i } << '\n';
        << std::bitset < 8 * sizeof(int)>( i ) << '\n';
Topic archived. No new replies allowed.