数字转字符串:
用C++的streanstream:
#include <sstream>
#Include <string>
string num2str(double i)
{
stringstream ss;
ss<<i;
return ss.str();
}
字符串转数字:
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/a41954a27d6ad96fa2c2cf816e677448.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6a9c071a08f1dae2d3e1c512000eef41.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/0196c3df5ea9e936f21e9932cca91014.gif)
上面方法很简便, 缺点是处理大量数据转换速度较慢..
C library中的sprintf, sscanf 相对更快可以用sprintf函数将数字输出到一个字符缓冲区中. 从而进行了转换...
例如:
已知从0点开始的秒数(seconds) ,计算出字符串"H:M:S", 其中H是小时, M=分钟,S=秒
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![c/c++ <wbr>数字转成字符串, <wbr>字符串转成数字](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)