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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -