char[] 转 数字
#incldue <cstdlib>
double atof (const char* str);
int atoi (const char * str);
long int atol ( const char * str );
long long int atoll ( const char * str );
float strtof (const char* str, char** endptr);
long double strtold (const char* str, char** endptr);
long long int strtoll (const char* str, char** endptr, int base);
unsigned long int strtoul (const char* str, char** endptr, int base);
unsigned long long int strtoull (const char* str, char** endptr, int base);
数字 转 char[]
#include <cstdio>
int sprintf ( char * str, const char * format, ... );
char[10] s;
sprintf(s, "%d", 123);
sprintf(s, "%5d%5d", 123, 4567);
string 和 char[] 互换
#include <string>
#include <cstring>
string -> char[]
string str ("Please split this sentence into tokens");
char cstr[str.length()];
strcpy (cstr, str.c_str());
char[] -> string
string a = cstr;
string b(cstr);
string 转 数字
#include <string>
int stoi (const string& str, size_t* idx = 0, int base = 10);
long stol (const string& str, size_t* idx = 0, int base = 10);
unsigned long stoul (const string& str, size_t* idx = 0, int base = 10);
long long stoll (const string& str, size_t* idx = 0, int base = 10);
unsigned long long stoull (const string& str, size_t* idx = 0, int base = 10);
float stof (const string& str, size_t* idx = 0);
double stod (const string& str, size_t* idx = 0);
long double stold (const string& str, size_t* idx = 0);
数字 转 string
#include <string>
string to_string (int val);
string to_string (long val);
string to_string (long long val);
string to_string (unsigned val);
string to_string (unsigned long val);
string to_string (unsigned long long val);
string to_string (float val);
string to_string (double val);
string to_string (long double val);