当我们需要将一个字符串与来自多个变量类型的数据连接起来时,我们通常会执行以下操作:
int year = 2013;
float amount = 385.5;
stringstream concat;
string strng;
concat << "I am in the year " << year << " and I don't have in my pocket but the amount " << amount;
strng = concat.str();
cout << strng << endl;
正如我们在该代码中看到的,我们连接了许多类型的数据:yearint类型、amountfloat类型和stringI am in the year类型。在其他编程语言中,您可以使用运算符来执行相同的操作。+
所以,回到这个问题:除了 stringstream, 连接字符串(char或string类型)之外C还有另一种方法C++吗?我希望能够用两种语言做到这一点。