一、使用stringstream 类
c++中的 <sstream>库定义了三种类:istringstream、ostringstream和stringstream,分别用来进行流的输入、输出和输入输出操作。

 

 

 

 

二、c++中 stoi
将 n 进制的字符串转化为十进制
示例:
stoi(str, 0, 2); //将字符串 str 从 0 位置开始到末尾的 2 进制转换为十进制


三、atoi、atof、atol、itoa等
C标准库<stdlib.h>提供了 atoi, atof, atol, atoll(C++11标准) 函数将字符串转换成int,double, long, long long 型。

而非标准函数itoa、litoa()、ultoa()可以将int、long、unsigned long型整数转换为字符串类型。