c++ tostring code example
Example 1: to_string c++
// to_string example
#include <iostream> // std::cout
#include <string> // std::string, std::to_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 2: int to string c++
#include<string>
string s = to_string(int_val);
Example 3: c++ string
#include <string>
std::string myString = "Hello, World!";
Example 4: c++ stirng
#include <string>