c++将数字和string 进行拼接

可以使用ostringstream进行拼接
举个例子

#include<iostream>
#include<ctime>
#include<sstream> 
using namespace std;
int main()
{
    ostringstream os;
    os<<"我已经玩王者荣耀"<<4<<"年了";
    //输出
	cout<<os.str() <<endl;
}

运行结果是
在这里插入图片描述
拼接完全不受限制

猜你喜欢

转载自blog.csdn.net/qq_45721778/article/details/106179712