c/c++ string和double类型互转

来源:互联网 发布:查找算法 编辑:程序博客网 时间:2024/05/29 09:35
#include <stdio.h>#include <stdlib.h>#include <iostream>#include <string>using  namespace std;int main(){    //double->string    char buffer[100];    double b=1245683.141592653;    int ndight=20;//有效数字位数    gcvt(b,ndight,buffer);    cout<<buffer<<endl;    //string->double    string str="1245683.141592653";    double num=atof(str.c_str());    printf("%0.9lf\n",num);}


0 0
原创粉丝点击