C++中最简单的方法是从 int >代码转换为等效的字符串。我知道有两种方法。有没有更简单的方法
(一)
inta=10;
char*intStr=itoa(a);
字符串str=字符串(intStr);
(二)
inta=10;
细流ss;
ss<&书信电报;A.
字符串str=ss.str();
C++11引入了std::stoi(以及每种数字类型的变体)和std::to_string,它们是Catoi和itoa的对应项,但用std::string表示
#包括<;字符串>;
std::string s=std::to_string(42);
因此,这是我能想到的最短的方法。您甚至可以使用auto关键字省略对类型的命名:
自动s=std::to_字符串(42);
注意:请参见[string.conversions](21.5在n3242中)