首页 > 系统服务 > 详细

linux int to string 方法

时间:2014-11-11 02:00:12      阅读:423      评论:0      收藏:0      [点我收藏+]

最近从windows 移植程序的时候发现to_string()函数在linux 中不能用,网上找了几种方法,觉得使用stringstream对象来实现类型转化比较好一点。

你只需在你工程中加入下面的to_sting()函数,就不需要修改你原程序了。(这篇只是本人移植工程时的心得,高手绕过!)

/*
 * to_string.cpp
 *  Created on: 2014年9月11日
 * Author: tursunjan
 *      linux int to string
 */
#include<iostream>
#include<sstream>
using namespace std;
string to_string(int a)
{
   ostringstream ostr;
   ostr << a;
   string astr = ostr.str();
   //cout << astr <<endl;
   return astr ;
}
int main()
{
    int testNum=10;
    cout<<to_string(testNum)<<endl;
    return 0;
}

 





linux int to string 方法

原文:http://www.cnblogs.com/ali412/p/4088591.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!