Search notes:
Create a std::string representation of a numerical value with std::to_string (C++ Standard Library)
std::string
takes a numerical value as input parameter and returns a std::string
that represents the numerical value.
//
// g++ -std=c++11 to_string.cpp
//
#include <string>
#include <iostream>
int main() {
std::string res;
bool b = true ; res = std::to_string(b); std::cout << res << std::endl; // 1
float f = 123.45678901; res = std::to_string(f); std::cout << res << std::endl; // 123.456787
double d = 123.45678901; res = std::to_string(d); std::cout << res << std::endl; // 123.456789
long l = 123456789012; res = std::to_string(l); std::cout << res << std::endl; // 123456789012
}