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 ...
随机推荐
- os/exec
用go来执行命令 cmd := exec.Command(命令,参数1,参数2....) out, _ := cmd.Output() data := string(out) Output得到的是正常 ...
- C# 窗体 类似framest 左侧点击右侧显示 左侧菜单右侧显示
首先托一个splitContainer调节大小位置 然后进行再新创建一个窗体名为add 在左侧拖入button按钮 进入代码阶段 更改属性 public Main() { InitializeComp ...
- IISPUT 批量脚本的编写
import requests import re import sys header = { "Accept":"text/javascript, applicatio ...
- elasticsearch sql插件 2.4及以下版本配置
github地址:https://github.com/NLPchina/elasticsearch-sql/ 方式一:github elasticsearch-sql上提供的安装方法cmd进入到本地 ...
- ios编译库文件时出现的问题
1. 警告:directory not found for option "xxxxxxxx" 文件路径未找到 选择工程, 编译的 (targets) 选择 Build Setti ...
- Linux设备驱动程序 之 tasklet
多数情况下,为了控制一个寻常的硬件设备,tasklet机制都是实现自己下半部的最佳选择:tasklet可以动态创建,使用方便,执行起来还算快: 声明tasklet tasklet既可以静态的创建,也可 ...
- [Java] JRE、JDK和JVM的区别
在Java语言的学习过程中,配置环境时首先会接触到JRE和JDK的概念,后面随着了解的深入,不可避免会学习到JVM. JRE,全称Java Runtime Environment,也被写成Java R ...
- The problem is now the wait_for_fds() example function: it will call something like select(), poll() or the more modern epoll() and kqueue().
小结: 1.线程与惊群效应 Serializing accept(), AKA Thundering Herd, AKA the Zeeg Problem — uWSGI 2.0 documentat ...
- 《maven实战》笔记(2)----一个简单maven项目的搭建,测试和打包
参照<maven实战>在本地创建对应的基本项目helloworld,在本地完成后项目结构如下: 可以看到maven项目的骨架:src/main/java(javaz主代码)src/test ...
- JDBC的异常处理方式
A: try...catch(...) {...} finally {} B: 关闭ResultSet,Statement , Connection import java.sql.Connectio ...