微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

当我尝试通过 static_cast 将 uint_fast8_t 转换为 bitset<8> 时,我收到一个奇怪的错误

如何解决当我尝试通过 static_cast 将 uint_fast8_t 转换为 bitset<8> 时,我收到一个奇怪的错误

例如;当我写 3 时,我得到 00110011

6 -> 00110110

69 -> 00110110

我使用了 int8_t、uint8_t、uint_least8_t 等。我得到了同样的错误。 0011开头的原因是什么?我使用的是 Visual Studio 和 Windows10。

#include <bitset>
#include <cstdint>
#include <iostream>

int main()
{
    std::uint_fast8_t numb;
    std::cout << "Please type an unsigned integer (0-255): ";
    std::cin >> numb;
    std::bitset<8> bits = static_cast<std::bitset<8>>(numb);
    std::cout << bits << '\n';
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。