0

Previously I noticed that GCC has built-in support for 128-bit integer. now I'm trying it under MinGW but there are two problems with that:

  1. I can't print it using cout.
  2. I can't convert it to string neither by string's constructor nor by functions like to_string().

here is the code:

#include <iostream>

using namespace std;

int main() {
    __int128 a = 12;
    cout << a;
    
    return 0;
}
Use of overloaded operator '<<' is ambiguous (with operand types 'std::ostream' (aka 'basic_ostream<char>') and '__int128')

My guess is to overload << operator for cout... but I don't know how?!

Also why cout doesn't have support for __int128 when this is a built-in type?!

  • 4
    std::cout is part of the C++ Standard. __int128 is not part of the C++ Standard. It is a GCC extension (other compilers don't offer it) If the standard doesn't have a 128 bit integer then you have to use GCC extensions to print it (they have one for printf) or make your own. Here is a related question: https://stackoverflow.com/questions/25114597/how-to-print-int128-in-g https://stackoverflow.com/questions/11656241/how-to-print-uint128-t-number-using-gcc – Jerry Jeremiah Sep 09 '21 at 05:17
  • @JerryJeremiah thanks it helped! – Mohammad Mostafa Dastjerdi Sep 09 '21 at 05:34

0 Answers0