一。数字--string
(1)数字转string(c++11有的新方法)
例:
int i = 9;
string str = to_string(i);
(2)string转数字
stoi();stol();stoul();stoll();stoull();stof()
函数原型:int stoi (const string& str, size_t* idx = 0, int base = 10);
例:
int a;
string str = "1010";
a = stoi(str, 0, 2);//从0位置开始取2个数字
a为10
二。string -- char数组
(1)string转char数组
char *p;
string str = "hello";
p = str.c_str();
(2)char数组转string
直接转
char a[10] = "hello";
string str(a);