如何在C ++编程中将char和integer附加到字符串
例如,
int value_of_int = 100;
char value_of_char[20] = "HELLO";
string result_line;
result_line << value_of_int;
result_line << value_of_char;
vector<string> result_set;
result_set.push_back(result_line);
int和char的值将被更改,并希望保存vector<string>.
答案 0 :(得分:2)
您可以使用ostringstream
:
int value_of_int = 100;
char value_of_char[20] = "HELLO";
std::ostringstream result_line; // #include <sstream>
result_line << value_of_int << value_of_char;
vector<string> result_set;
result_set.push_back(result_line.str());