在C++中,你可以使用std::stringstream来实现字符串拼接。下面是一个简单的示例:
#include <iostream>
#include <sstream>
#include <string>
int main() {
std::stringstream ss;
// 拼接字符串
ss << "Hello, " << "World!" << std::endl;
// 从stringstream中获取拼接后的字符串
std::string result = ss.str();
// 输出结果
std::cout << result << std::endl;
return 0;
}
在这个示例中,我们创建了一个std::stringstream对象ss,然后使用<<操作符将字符串拼接在一起。最后,我们使用str()方法从stringstream对象中获取拼接后的字符串,并将其存储在result变量中。
辰迅云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
推荐阅读: stringstream有哪些性能特点