iostream重载__int128
Normal (Naive)写法,用 string(char* )
std::ostream& operator <<(std::ostream&out,const __int128 b) {
std::string s; __int128 t = b;int sig = 1;
if(t < 0) sig = -1,t = -t;
for(;t;t/=10) s += '0' + t % 10;
if(sig == -1) s += '-';
reverse(s.begin(), s.end());
if(s.length() == 0) s += '0';
out << s ;
return out;
}
/********* istrream 类似读入挂 O(∩_∩)O *************/
我突然有个大胆的想法系列
std::ostream& operator <<(std::ostream&out, __int128 x) {
if(x < 0) {out << "-"; out << -x; return out;}
if(x == 0) {out << "0"; return out;}
if(x > 10) out << x / 10;
out << "0123456789"[x % 10];
return out;
}
std::istream& operator >>(std::istream&in, __int128 &x) {
char c;
while(c = in.get(), c != '-' && !isdigit(c));
if(c == '-') {x = '0' - (c = in.get()); while(isdigit(c = getchar()))x = x * 10 + '0' - c;}
else {x = c - '0'; while(isdigit(c = in.get()))x = x * 10 - '0' + c;};
return in;
}
iostream重载__int128的更多相关文章
- C++ 运算符重载时,将运算符两边对象交换问题.
在C++进行运算符重载时, 一般来讲,运算符两边的对象的顺序是不能交换的. 比如下面的例子: #include <iostream> using namespace std; class ...
- c++文件输入输出流fstream,对输入>>和输出<<重载
1. fstream 继承自iostream --> 要包含头文件#include<fstream> 2. 建立文件流对象 3. 打开文件夹 4. 测试是否打开成功 5. 进行读写操 ...
- 虚函数的使用 以及虚函数与重载的关系, 空虚函数的作用,纯虚函数->抽象类,基类虚析构函数使释放对象更彻底
为了访问公有派生类的特定成员,可以通过讲基类指针显示转换为派生类指针. 也可以将基类的非静态成员函数定义为虚函数(在函数前加上virtual) #include<iostream> usi ...
- c++面试常用知识(sizeof计算类的大小,虚拟继承,重载,隐藏,覆盖)
一. sizeof计算结构体 注:本机机器字长为64位 1.最普通的类和普通的继承 #include<iostream> using namespace std; class Parent ...
- C++运算符重载
C++运算符重载 基本知识 重载的运算符是具有特殊名字的函数,他们的名字由关键字operator和其后要定义的运算符号共同组成. 运算符可以重载为成员函数和非成员函数.当一个重载的运算符是成员函数时, ...
- 标准C++之运算符重载和虚表指针
1 -> *运算符重载 //autoptr.cpp #include<iostream> #include<string> using namespace std ...
- STL学习之运算符(<<)重载问题和仿函数的实现
/* 运算符<<的重载一直报错, 友原函数中可以访问到类的私有成员*/#include<iostream>using namespace std; class MyIn ...
- Javascript函数重载,存在呢—还是存在呢?
1.What's is 函数重载? );//Here is int 10 print("ten");//Here is string ten } 可以发现在C++中会根据参数的类型 ...
- javascript 函数重载 overloading
函数重载 https://en.wikipedia.org/wiki/Function_overloading In some programming languages, function over ...
随机推荐
- leetcode解题报告(3):Search in Rotated Sorted Array
描述 Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 m ...
- Noip2014 提高组 Day1 T1 生活大爆炸版石头剪刀布 + Day2 T1 无线网络发射器选址
Day1 T1 题目描述 石头剪刀布是常见的猜拳游戏:石头胜剪刀,剪刀胜布,布胜石头.如果两个人出拳一样,则不分胜负.在<生活大爆炸>第二季第8 集中出现了一种石头剪刀布的升级版游戏. 升 ...
- Java分布式互联网架构/微服务/高性能/springboot/springcloud 2018年10月17日直播内容
2018年10月17日直播内容 大规模并发必备的消息中间件技术ActiveMq 网盘链接: https://pan.baidu.com/s/1GlxsZ2JnrvX- YN16-S7lQw 提取码: ...
- Win内核原理与实现学习笔记3-windows系统结构
1.概述 1.1windows采用了双模式(dual mode)结构来保护操作系统本身,以避免被应用程序的错误而波及.操作系统核心运行在内核模式(kernel mode)下,应用程序的代码运行在用户模 ...
- 中国传统色彩名录及其RGB值
- WGAN实验环境搭建
"TensorFlow在Windows上支持Python 3.5.x和3.6.x." 因此,您无法在Windows上使用Python 2.7的tensorflow windows+ ...
- 字符串匹配(KMP&BF)
字符串匹配 题目描述 设计一个程序,从一个主字符串中查找一个子字符串在主串中第一次出现的位置.主串和子串的长度不超过100.如果找不到,则输出-1. 程序输入说明 第一行输入一个整数N,说明需要进 ...
- 线上bug或故障界定及填写规范
[线上故障与线上Bug界定] 一.线上故障: 1. 故障参照公司规范稍做调整: a) 1级故障:资讯首页或主App首页无法打开:多条业务线同时不可用:超过15分钟: b) ...
- PyTricks-Differebt ways to test multiple flags at once in
x, y, z = 0, 1, 0 if x == 1 or y == 1 or z == 1: print('passed') if 1 in (x, y, z): print('passed') ...
- pwn学习日记Day6 基础知识积累
知识杂项 ELF:在计算机科学中,是一种用于二进制文件.可执行文件.目标代码.共享库和核心转储格式文件. char fgets(char buf, int bufsize, FILE stream); ...