首页 > 编程语言 > 详细

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

时间:2019-12-29 10:50:54      阅读:69      评论:0      收藏:0      [点我收藏+]

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转为字符串

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

原文:https://www.cnblogs.com/briskzou/p/12083480.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!