gpt4 book ai didi

c++ - 如何打印 unsigned long long 的所有可能的唯一位掩码?

转载 作者:行者123 更新时间:2023-11-30 04:19:55 24 4
gpt4 key购买 nike

有一个 unsigned long long 如何将它以 hex 掩码的形式打印到 std::string 中?

我尝试遍历二进制(值如 000100100100)掩码:

std::stringstream str;
std::string result;
for (unsigned long long mask = 1; mask != 0; mask <<= 1) {
str << mask;
str >> result;
std::cout << result << std::endl;
str.flush();
}

但我只看到值 == 1(请参阅 live sample here)。

所以我想知道如何打印 unsigned long long 所有可能的唯一位掩码?

最佳答案

您需要使用 str.clear(),而不是 str.flush()。并查看 this对于十六进制部分

关于c++ - 如何打印 unsigned long long 的所有可能的唯一位掩码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15497840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com