Skip to content

Instantly share code, notes, and snippets.

@fresky
Last active December 17, 2015 00:49
Show Gist options
  • Save fresky/5524148 to your computer and use it in GitHub Desktop.
Save fresky/5524148 to your computer and use it in GitHub Desktop.
python style print in C++
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