string, char*, const char*, int type conversion
//------------------------------------------//
//------------------------------------------//
std::istringstream ( str ) >> i;
std::istringstream ( str ) >> f;
std::istringstream ( str ) >> d;
//------------------------------------------//
#include <boost/lexical_cast.hpp>
int i = boost::lexical_cast<int>( str.c_str());
float f = boost::lexical_cast<int>( str.c_str());
double d = boost::lexical_cast<int>( str.c_str());
} catch( boost::bad_lexical_cast const&amp;amp; ) {
https://stackoverflow.com/questions/347949/how-to-convert-a-stdstring-to-const-char-or-char/4152881#4152881
char* strtoch(string str){
char *cstr = new char[str.length() + 1];
strcpy(cstr, str.c_str());
//------------------------------------------//
std::string x = "hello world";
const char* p_c_str = x.c_str();
const char* p_data = x.data();
char* p_writable_data = x.data(); // for non-const x from C++17
char* p_x0_rw = &x[0]; // compiles if x is not const...
//------------------------------------------//
std::vector<char> cstr(str.c_str(), str.c_str() + str.size() + 1);
std::vector<char> writable(str.begin(), str.end());
writable.push_back('\0');
char* to int
int atoi(const char *nptr);
long atol(const char *nptr);
long long atoll(const char *nptr);
long long atoq(const char *nptr);
char to int
// read the value as an ascii code
int num = static_cast<int>(letter); // if letter='a', num=97
//------------------------------------------//
//convert the character '0' -> 0, '1' -> 1, etc
int ia = a - '0'; // a - '0' is equivalent to ((int)a) - ((int)'0')
char c = i; // c='1' 49=1
char c = (char)i; // c='1' 49=1
char c = '0'+i; // c='a' 48+49=97=a
char *c = itoa(i,buffer,10);
std::string s = std::to_string(i);
auto s = std::to_string(i);
string str = string(intStr);
std::string NumberToString ( T Number )
#include <boost/lexical_cast.hpp>
std::string str = boost::lexical_cast<std::string>(num);