gpt4 book ai didi

c++ - 在 C++11 中可移植地打印 std::uint64_t 变量的格式说明符

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:03:33 25 4
gpt4 key购买 nike

打印 std::uint64_t 类型值的格式说明符是什么? (来自 <cstdint> )使用来自 std::printf() 的函数C++ 中的家庭?

C99 有 PRIu64 (来自 <inttypes.h> )但我并不完全清楚 PRIu64是有效的 C++11,虽然我能找到它可能是的提示。

没有PRIu64 ,据我所知,没有一种格式说明符适用于所有情况:

  • 在 32 位平台上,std::uint64_t将被定义为 unsigned long long并且格式说明符将为 %llu .
  • 在 64 位平台上,std::uint64_t将被定义为 unsigned long并且格式说明符将为 %lu .
  • 但是对于 Visual Studio,%llu在这两种情况下都有效。

最佳答案

PRIu64仍然是您将在 C++ 中使用的内容。每[cinttypes.syn] PRIu64

[...]

#define PRIuN see below

[...]

The contents and meaning of the header <cinttypes> are the same as the C standard library header <inttypes.h> [...]

因此它存在并且具有与 C ISO/IEC 9899:2011 标准中相同的行为。

关于c++ - 在 C++11 中可移植地打印 std::uint64_t 变量的格式说明符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56172857/

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