#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;
}
#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;
}
作者:jackxiang@向东博客 专注WEB应用 构架之美 --- 构架之美,在于尽态极妍 | 应用之美,在于药到病除
地址:https://jackxiang.com/post/705/
版权所有。转载时必须以链接形式注明作者和原始出处及本声明!
最后编辑: jackxiang 编辑于2007-10-25 17:53
评论列表