- #include <iostream>
- namespace __hidden__ {
- struct print {
- bool space;
- print() : space(false) {}
- ~print() { std::cout << std::endl; }
- template <typename T>
- print &operator , (const T &t) {
- if (space) std::cout << ' ';
- else space = true;
- std::cout << t;
- return *this;
- }
- };
- }
- #define print __hidden__::print(),
- int main() {
- int a = 1, b = 2;
- print "this is a test";
- print "the sum of", a, "and", b, "is", a + b;
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1807201410017.html
来源: http://www.codesnippet.cn/detail/1807201410017.html