#include <iostream>
#include <string>
std::string addTwoStrings(const std::string& a, const std::string& b)
{
return a + b; // works because they are both strings.
}
void foo(const char* a, const char* b)
{
std::string str = a;
std::cout << "1st str = [" << str << "]" << std::endl;
str += " ";
std::cout << "2nd str = [" << str << "]" << std::endl;
str += b;
std::cout << "3rd str = [" << str << "]" << std::endl;
str = addTwoStrings(a, " ");
std::cout << "4th str = [" << str << "]" << std::endl;
str = addTwoStrings(str, b);
std::cout << "5th str = [" << str << "]" << std::endl;
}
int main()
{
foo("hello", "world");
}
ICAgICNpbmNsdWRlIDxpb3N0cmVhbT4KICAgICNpbmNsdWRlIDxzdHJpbmc+CgogICAgc3RkOjpzdHJpbmcgYWRkVHdvU3RyaW5ncyhjb25zdCBzdGQ6OnN0cmluZyYgYSwgY29uc3Qgc3RkOjpzdHJpbmcmIGIpCiAgICB7CiAgICAgICAgcmV0dXJuIGEgKyBiOyAvLyB3b3JrcyBiZWNhdXNlIHRoZXkgYXJlIGJvdGggc3RyaW5ncy4KICAgIH0KCiAgICB2b2lkIGZvbyhjb25zdCBjaGFyKiBhLCBjb25zdCBjaGFyKiBiKQogICAgewogICAgICAgIHN0ZDo6c3RyaW5nIHN0ciA9IGE7CiAgICAgICAgc3RkOjpjb3V0IDw8ICIxc3Qgc3RyID0gWyIgPDwgc3RyIDw8ICJdIiA8PCBzdGQ6OmVuZGw7CiAgICAgICAgc3RyICs9ICIgIjsKICAgICAgICBzdGQ6OmNvdXQgPDwgIjJuZCBzdHIgPSBbIiA8PCBzdHIgPDwgIl0iIDw8IHN0ZDo6ZW5kbDsKICAgICAgICBzdHIgKz0gYjsKICAgICAgICBzdGQ6OmNvdXQgPDwgIjNyZCBzdHIgPSBbIiA8PCBzdHIgPDwgIl0iIDw8IHN0ZDo6ZW5kbDsKICAgICAgICBzdHIgPSBhZGRUd29TdHJpbmdzKGEsICIgIik7CiAgICAgICAgc3RkOjpjb3V0IDw8ICI0dGggc3RyID0gWyIgPDwgc3RyIDw8ICJdIiA8PCBzdGQ6OmVuZGw7CiAgICAgICAgc3RyID0gYWRkVHdvU3RyaW5ncyhzdHIsIGIpOwogICAgICAgIHN0ZDo6Y291dCA8PCAiNXRoIHN0ciA9IFsiIDw8IHN0ciA8PCAiXSIgPDwgc3RkOjplbmRsOwogICAgfQoKICAgIGludCBtYWluKCkKICAgIHsKICAgICAgICBmb28oImhlbGxvIiwgIndvcmxkIik7CiAgICB9Cg==