c++中, 整型和字符型常量怎么实现相加? 然后以字符型常量输出..

来源:百度知道 编辑:UC知道 时间:2024/05/27 20:45:58
c++中, 整型和字符型常量怎么实现相加? 然后以字符型常量输出..例如,我现在有 string wor = "tbs"
int a = 12
int b = 11
我希望得到 string word = "tbs&11&12&" 这么一串字符,然后输出..
打错了..是字符串型常量..

#include<stdlib.h>

string wor = "tbs"
int a = 12
int b = 11

wor=wor+ itoa(a)+itoa(b)

string可能也有format类方法吧

这个吗。。。

string word = "tbs&11&12&"
这种不是整型和字符型常量相加,这是在字符串后面增加字符.
还有一个概念要弄清楚,常量是不能相加赋值的.

MFC工程中是这样的 :

CString str = "tbs";
int a = 12 ;
int b = 11 ;
CString str1;
str1.Format("%s&%d&%d", str, b,a);
要输出的话 随便show个对话框出来,加上MessageBox(str1);这句