java - System.out.println function syntax in C++ -
i want create function in c++ using cout has same println function in java. means call should this:
int a=5 println("a string" + a);
the variable should have basic type. kind of parameter should have in case , how work?
thanks
as larsmans pointed out, java has overloads on operator +. can concat strings integer. possible in c++ not out of box types.
you use templated functions this.
#include <iostream> using namespace std; template <typename t> void printer(t t) { cout << t << endl; } template <typename t, typename ...u> void printer(t t, u ...u) { cout << t; printer(u...); } int main() { int a=5; printer("a string ", a); return 0; }
but recommend take @ boost::format. guess library want.
Comments
Post a Comment