System.out.println function syntax in C++

As larsmans already pointed out, java has overloads on the operator +. So you can concat strings with integer. This is also possible in C++ but not out of the box for all types.

You could use a templated functions like 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 I would recommend to take a look at boost::format. I guess this library will do what you want.

Leave a Comment