If you want some variable shown, cout << will take case of of printing. If you need a string, there is a stringstream class, which looks like cout, but doesn't print anything and you can get the result with str() method. For other cases, like a class of your own, either overload operator << or write a to_string() method.