本人在做一道需要使用 __int128 的题,为方便输出写了如下的输出函数:
inline ostream& operator <<(ostream &ouf,i128 x){
static char sta[1024];static int top;top=0;
if(x<0)ouf<<'-',x=-x;
do sta[++top]=x%10^48,x/=10; while(x);
while(top)ouf<<sta[top--];
return ouf;
}
然而我在使用它生成数据时,却发现它有时候会输出乱码,经过调试发现输出了负数的 char 值,但在 do-while 部分 assert x>=0、x%10>=0、(x%10^48)>=0 均无果,同时如果尝试在 do-while 部分输出 x 会 RE,在 while(top) 部分 assert sta[top]>=0 会 Assertion Failed。
求问这是什么原因。