C ++如何将char和integer附加到字符串

时间:2012-03-31 06:04:01

标签: c++ string vector integer char

如何在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>.

1 个答案:

答案 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());