跳到正文

个人记录

忘记删除调试输出语句不要方, 编译选项+宏解君忧愁

钾肥约 3 分钟
原文
文章信息与版本

文章信息

发布
2021年4月9日
收录
2026年8月20日
更新
2026年8月20日
篇幅
约 3 分钟
获赞
1

版本

  1. v1当前

个人博客传送门

原因

研究这个的原因很简单, 忘记删输出语句导致白给很多次.

由于众所周知的原因, 我很担心因为这个打铁(其实解决了这个问题照样打铁, 改变不了当废物的事实)

完整代码

C++
#include <cstdio>
#include <iostream> 

using namespace std;

#ifdef LOCAL
#define debug(format, args...) \
printf(format, ##args)
#define dbg(args...) __f(args)
template <typename Arg1>
void __f(const Arg1& arg1){
	cout << arg1;
}
template <typename Arg1, typename... Args>
void __f(const Arg1& arg1, const Args&... args){
	cout << arg1;
	__f(args...);
}
#else
#define debug(format, args...)
#define dbg(...)
#endif

int main(){
	#ifndef LOCAL
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	#endif 
	int a = 1, b = 2, c = 3, d = 4;
	debug("%d %d %d %d\n", a, b, c, d);
	dbg(a, ' ', b, ' ', c, ' ', d, '\n');
	return 0;
}

食用指南

printf()版本按照正常的printf()使用就可以了.

cout版本需要把流运算符换成逗号, 并且需要自行添加空格和换行(或者在封装的函数里面加), 实测重载输出流后的自定义类型也能输出.

编译选项中加上”-DLOCAL”就行了, 具体操作可以看 “算法竞赛入门经典” 的附录部分.

GCC -D选项: 编译时添加宏定义

解析

#, ##, args…以及__VAR_ARGS__宏定义解析

cout版本使用的是可变参数模板, 具体内容自行百度(因为是照着板子改的, 所以我也讲不清楚).

原文