C++: string 转 int ;string转float;int 转string;double转char*

1、string转int

std::string str1="700"
 int bid_v1 = atoi(str1.c_str());


2、string转float

std::string str2="6.78"
float bid_p1 = atof(str2.c_str());


3、int 转string

int n =789;
char t[256];
sprintf(t, "%d", n);
string s(t)

4、double转char*

char str[255];
sprintf(str, "%f", 10.8); //将10.8转为字符串

猜你喜欢

转载自www.cnblogs.com/briskzou/p/12083480.html