Adding to the explanation of @songyuanyao, you can do this either by using the +
operator of std::string
:
const std::string left = "Hello ";
const std::string right = "World";
const std::string point = "!";
std::cout << left + right + point << std::endl;
or by manipulating the output directly with std::cout
:
const std::string left = "Hello";
const std::string right = "World";
const std::string point = "!";
std::cout << left << " " << right << point << std::endl;
Or by using the printf
function (don't forget to #include <stdio.h>
):
const std::string left = "Hello";
const std::string right = "World";
const std::string point = "!";
printf("%s %s%s\n", left.c_str(), right.c_str(), point.c_str());
Look at this post if you want to know what the c_str()
is about.