to_string function in c++ code example
Example 1: change int to string cpp
#include <string>
std::string s = std::to_string(42);
Example 2: to_string c++
#include <iostream>
#include <string>
int main ()
{
std::string pi = "pi is " + std::to_string(3.1415926);
std::string perfect = std::to_string(1+2+4+7+14) + " is a perfect number";
std::cout << pi << '\n';
std::cout << perfect << '\n';
return 0;
}
Example 3: change integer to string c++
string str_val = to_string(int_val);
Example 4: to_string in c++
int i=11;
string str= to_string(i);