[英]Output 128 bit integer using stream operator
I'm using GCC's 128 bit integer:我正在使用 GCC 的 128 位 integer:
__extension__ using uint128_t = unsigned __int128;
uint128_t a = 545;
std::cout << a << std::endl;
However, if I try to output using the stream operator I get the compiler error:但是,如果我尝试使用 stream 运算符访问 output,则会出现编译器错误:
error: ambiguous overload for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘uint128_t’ {aka ‘__int128 unsigned’})
Is there a way to allow this?有没有办法允许这样做?
Linux, GCC version 11.1, x86-64 Linux、GCC 版本 11.1、x86-64
libstdc++ does not have an ostream
overload for __int128
. libstdc++ 没有__int128
的ostream
重载。 However, you can use C++20 <format>
library, which supports __int128
formatting in both libstdc++ and libc++.但是,您可以使用 C++20 <format>
库,它在 libstdc++ 和 libc++ 中都支持__int128
格式。
#include <format>
#include <iostream>
int main() {
__extension__ using uint128_t = unsigned __int128;
uint128_t a = 545;
std::cout << std::format("{}\n", a);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.