Last active
December 17, 2015 00:49
-
-
Save fresky/5524148 to your computer and use it in GitHub Desktop.
python style print in C++
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment