I want to convert an integer to a string. I tried it this way but this didn't work
void foo()
{
int y = 1;
string x = static_cast<string>(y);
}
The std::to_string
function should do it:
string x = std::to_string(y);
For the opposite, it's std::stoi
:
int z = std::stoi(y, nullptr, 10);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With