【C++】A trick I learned:put boilerplate code into constructor of a struct
2024-10-07 00:54:37
I learned this trick from hitonanode's submission on AtCoder.
The trick is like
struct fast_ios {
fast_ios(){
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
}
} fast_ios_;
What I used to do is like
#define FAST_READ ios::sync_with_stdio(false); cin.tie(nullptr);
int main() {
FAST_READ
cout << fixed << setprecision(10);
// ...
}
using this trick, the code becomes
struct fast_ios { fast_ios(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(10); } } fast_ios_;
int main() {
// ...
}
I think macros are better avoided when alternatives are available.
Update 2020/5/21
There is another way to achieve the same function:
int fast_io = []() {
cin.tie(0);
ios::sync_with_stdio(false);
cout << fixed << setprecision(20);
return 0;
}();
最新文章
- 【转】 iOS9.2-iOS9.3.3越狱插件清单
- CSS3媒体查询使用小结
- Windows下Nginx的安装与配置(转)
- nginx:配置详细说明
- editplus文本编辑器
- 《Apache服务用户身份验证管理》RHEL6.3
- 【Servlet】doGet()与doPost()的区别
- Linux read语法及浅析
- tar 基础
- Beijing Perl Workshop - Augest 10th, 2013
- 理解free命令
- [国嵌攻略][179][OpenSSL加密系统]
- Exchange Server 2010升级到Exchange Server 2016
- jsp面试题
- np.mgrid 用法
- 第四篇:记录相关操作 SQL逻辑查询语句执行顺序
- 20180323 DataTable增加DataRow方式优化
- IDEA 热部署- 自动编译设置
- 吴裕雄 数据挖掘与分析案例实战(10)——KNN模型的应用
- iOS UITextField的代理<;UITextFieldDelegate>;的几点笔记
热门文章
- DB 分库分表(4):多数据源的事务处理
- [心得]暑假Day 8
- IDEA:Process finished with exit code -1073741819 (0xC0000005)
- 【全网最优方法】JAVA初学:错误: 找不到或无法加载主类HelloWorld
- GLSL语法入门
- is幻梦 Linux命令之文件和目录操作命令(二)——查看文件内容cat、more、less、tail、head
- 【React自制全家桶】六、React性能优化(持续更新总结)
- UML学习笔记_02_UML初识(简单的流程)
- C++中 关于操作符的重载
- Maven 默认 SpringMVC-servlet.xml 基本配置