c++版本的转换和c版本转换

| |
| October 25, 2007 17:52 | root | Via 本站原创
#include <stdio.h>
#include <string>
#include <sstream>

using namespace std;

int main(void)
{
       string a = "312.29";
       string b;
       float f;
       stringstream mm;

       mm << a;
       mm >> f;
       printf("f=[%f]\n", f);

       mm.clear();
       mm << f;
       mm >> b;
       printf("b=[%s]\n", b.c_str());

       return 0;
}


#include <stdio.h>
#include <math.h>
#include <string>
using namespace std;
int main(void)
{
       float f;
       string a = "312.29";
       char c[100];
       string b;

       f = atof(a.c_str());
       printf("f=[%f]\n", f);

       if (f>2008)
               printf("more than 2008\n");
       else
               printf("less than 2008\n");

       sprintf(c, "%f", f);
       printf("c=[%s]\n", c);

       b = c;
       printf("b=[%s]\n", b.c_str());

       return 0;
}
WEB相关 | 评论(0) | 引用(0) | 阅读(245)
发表评论
 网址
 电邮
  密码 游客无需密码
 昵称  *  [注册]
               

 
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我