float 如何转化为字符串类型

对于float   f;    
方法1:  char   buf[32];  
snprintf(buf,   sizeof(buf),   "%f ",   f);  
string   s   =   buf;    
方法2:  
#include   <stdlib.h>  
char   buf[32];  _gcvt(f,   16,   buf);  
string   s   =   buf;    
方法3:  #include   <sstream>  
ostringstream   oss;  
oss   < <   f;  string   s   =   oss.str();    
方法4:  //使用boost库:  
string   s   =   boost::lexical_cast <string> (f); 

 

posted @ 2013-01-22 18:46  冷夜 - 网游编程技术  阅读(766)  评论(0编辑  收藏  举报