我有一个字符串,我需要给它添加一个数字,即一个int。像:我如何添加一个int到一个字符串
string number1 = ("dfg");
int number2 = 123;
number1 += number2;
这是我的代码:
name = root_enter; // pull name from another string.
size_t sz;
sz = name.size(); //find the size of the string.
name.resize (sz + 5, account); // add the account number.
cout << name; //test the string.
这个工程...有点,但我只得到了 “名* 88888” 和...我不知道为什么。 我只需要一种方法来将int的值添加到字符串的末尾
“我不知道为什么”。 “resize”的第二个参数是一个char,并且resize重复使用它来填充它在字符串末尾创建的任何额外空间。在你的情况下'account'等于56(mod 256),所以你已经传递了字符'8'。 – 2010-03-07 02:22:59