将float转换为字符串 [英] convert float to string

查看:148
本文介绍了将float转换为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

将双面转换为字符串C ++?

页面,但我还没有找到解决方案。

I searched in the page but i haven't found the solution.

我有一个方法从int转换为字符串。但现在我需要从float / double转换为字符串。因为我想在文件中写一些数据。

I have a method to convert from int to string. But now i need to convert from float/double to string. Because i want to write some data in a file.

任何人都可以帮助我。

推荐答案

http://www.daniweb.com/software-development/cpp/threads/146718

#include <sstream>
std::string Convert (float number){
    std::ostringstream buff;
    buff<<number;
    return buff.str();   
}

这篇关于将float转换为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆