Skip to content

Instantly share code, notes, and snippets.

@charasyn
Created October 5, 2018 06:57
Show Gist options
  • Save charasyn/176b62d27b1ec6994c82c69d306b10a1 to your computer and use it in GitHub Desktop.
Save charasyn/176b62d27b1ec6994c82c69d306b10a1 to your computer and use it in GitHub Desktop.
Python print in C++ (kinda, without named arguments)
// Written by Cooper H., released into the public domain or w/e license gist forces you to use
#include <iostream>
// thanks https://stackoverflow.com/questions/1657883/variable-number-of-arguments-in-c
template <typename T>
static void _print(const T & t) {
std::cout << t;
}
template<typename T, typename... Args>
static void _print(const T & t, Args... args) {
std::cout << t << " ";
_print(args...);
}
template<typename... Args>
static void print(Args... args) {
_print(args...);
std::cout << std::endl;
}
// Example:
int main() {
print("Hello World! A number:", 368-16/2, "A floating-point number:", 500.0/1234);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment