轉載來自:https://blog.csdn.net/HumveeA6/article/details/79806869
這種類型只有部分GCC編譯器支持。經測試,正常運算與普通int無異,但是輸入輸出時無論是cin,cout還是printf都會報錯,所以必須自己寫輸入輸出函數。
定義時與別的數據類型並沒有什么區別
eg: __int128 a,b,c;
輸入暫時采用字符串讀入方式。
方法一:重載輸出
std::ostream& operator<<(std::ostream& os, __int128 T) { if (T<0) os<<"-";if (T>=10 ) os<<T/10;if (T<=-10) os<<(-(T/10)); return os<<( (int) (T%10) >0 ? (int) (T%10) : -(int) (T%10) ) ; }
方法二:變為字符串式輸入輸出
輸入:
void scan(__int128 &x)//輸入 { x = 0; int f = 1; char ch; if((ch = getchar()) == '-') f = -f; else x = x*10 + ch-'0'; while((ch = getchar()) >= '0' && ch <= '9') x = x*10 + ch-'0'; x *= f; }
輸出:
void print(__int128 x) { if(x < 0) { x = -x; putchar(‘-‘); } if(x > 9) print(x/10); putchar(x%10 + ‘0‘); }
