stringstream has operator<< overload to insert data into the stream. It would return a reference to the stream itself so you can chain multiple insertions.
ss << str_one << str_two;
std::cout << ss.str(); // hello world!
As an alternate, you can leverage fold expression(since C++17) to concatenate multiple strings.
template<typename ...T>
std::string concat(T... first){
return ((first+ ", ") + ...);
}
int main(){
std::string a = "abc", b = "def", c = "ghi", d = "jkl";
std::cout << concat(a, b, c, d); // abc, def, ghi,
}
The fold expression is expanded as below:
"abc" + ("def" + ("ghi" + "jkl"));
Demo