我正在尝试使用许多字符串和整数来制作单个字符串,但我收到的消息是:“错误C2110:'+':无法添加两个指针”
这是我的代码:
transactions[0] = "New Account Made, Customer ID: " + ID + ", Customer Name : " + firstName + " " + secondName + endl + ", Account ID: " + setID + ", Account Name: " + setName;
(注意ID和setID是一个int)
答案 0 :(得分:2)
使用字符串流:
#include <sstream>
...
std::stringstream stm;
stm<<"New Account Made, Customer ID: "<<ID<<", Customer Name : "<<firstName<<" "<<secondName<<std::endl<<", Account ID: "<<setID<<", Account Name: "<<setName;
然后,您可以使用stm.str()访问生成的字符串。
答案 1 :(得分:1)
你应该使用字符串流:将字符串写入其中;然后写int。最后,通过流的str()
方法收集结果:
stringstream ss;
string hello("hello");
int world = 1234;
ss << hello << world << endl;
string res = ss.str();
cout << res << endl;