c++ 输出 变量名 字符串(zz.is2120.BG57IV3)

#define SHOW(a) std::cout << #a << ": " << (a) << std::endl
// ...
int i = 2;
SHOW (i);
//z 2013-01-29 16:19:23 IS2120@BG57IV3.T739790998 .K[T104,L1428,R47,V1454]
Hey, I like that macro. If you don't mind, I'm going to improve it just a little:
#define TO_STREAM(stream,variable) (stream) <<#variable": "<<(variable)

Here's an interesting (?) variation:

1
2
3
4
5
6
7
8
9
#include <iostream>

#define _(x) std::cout << #x << std::endl; x

int main() {
    _(int i = 0;)
    _(i = 1;)
    _(std::cout << i;)
}

原文地址:https://www.cnblogs.com/IS2120/p/6745774.html