<分区>
我想将整数转换为字符串。我这样试过,但没用
void foo()
{
int y = 1;
string x = static_cast<string>(y);
}
<分区>
我想将整数转换为字符串。我这样试过,但没用
void foo()
{
int y = 1;
string x = static_cast<string>(y);
}
最佳答案
std::to_string
函数应该这样做:
string x = std::to_string(y);
相反,它是std::stoi
:
int z = std::stoi(y, nullptr, 10);
关于c++ - 如何将整数转换为字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18989521/