最近从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=;
cout<<to_string(testNum)<<endl;
return ;
}

linux int to string 方法的更多相关文章

  1. C#部分---arraylist集合、arraylist集合中的object数据转换成int类string类等;间隔时间的表示方法;

    ArrayList和Array的区别: 相同点:1.两者都实现了IList.ICollection.IEnumerable接口:       2.两者都可以使用证书索引访问集合中的元素,包括读取和赋值 ...

  2. java中Object转换成int或String类型方法

    转载: http://www.cnblogs.com/1020182600HENG/p/6137206.html Object obj = getObject(); if(obj instanceof ...

  3. PDO 查询mysql返回字段int变为String型解决方法

    PDO 查询mysql返回字段int变为String型解决方法使用PDO查询mysql数据库时,执行prepare,execute后,返回的字段数据全都变为字符型. 例如id在数据库中是Int的,查询 ...

  4. 编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、 姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age) 用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—— TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测 试Stud

    package zuoye; public class student { int age; String name; int stuNO; void outPut() { System.out.pr ...

  5. C++ Daily 《4》----一个简单的 int to string 的方法

    经常会在项目中用到 int to string, 之前一般用C语言的 sprintf, 发现C++ 中的 ostringstream 可以轻松完成这个任务. #include <iostream ...

  6. 5.编写Java应用程序。首先,定义描述学生的类——Student,包括学号(int)、 姓名(String)、年龄(int)等属性;二个方法:Student(int stuNo,String name,int age) 用于对对象的初始化,outPut()用于输出学生信息。其次,再定义一个主类—— TestClass,在主类的main方法中创建多个Student类的对象,使用这些对象来测 试St

    Student类: package com.bao; public class Student { int stuNo;String name,sex;int age,weight; Student( ...

  7. 截取linux文件存储路径方法

    1.截取linux文件存储路径方法 package com.tydic.eshop.action.freemarker; public class dddd { public static void ...

  8. 微信录音文件上传到服务器以及amr转化成MP3格式,linux上转换简单方法

    微信公众号音频接口开发 根据业务需求,我们可能需要将微信录音保存到服务器,而通过微信上传语音接口上传到微信服务器的语音文件的有效期只有3天,所以需要将文件下载到我们自己的服务器. 上传语音接口 wx. ...

  9. C++ int转string(stringstream可转更多类型)

    一.使用atoi 说明: itoa(   int   value,   char   *string,   int   radix   );      第一个参数:你要转化的int;      第二个 ...

随机推荐

  1. 一次java程序的重构

    // com口操作类 package xyz.game; class ComOpera { public void openPort() throws Exception {...} // 打开com ...

  2. MySQL执行外部sql脚本

    1:-/mysql_test/test.sql create table student( sno int not null primary key auto_increment, sname ) n ...

  3. poj 3130 How I Mathematician Wonder What You Are!

    http://poj.org/problem?id=3130 #include <cstdio> #include <cstring> #include <algorit ...

  4. MFC关于VS内存释放的定位

    全部在App中完成 1.在 App.h 头文件声明 #ifdef _DEBUGprotected:      CMemoryState m_msOld, m_msNew, m_msDiff;#endi ...

  5. 18个SaaS及其功能评价

    SAAS软件及其功能评价1. 360 两个同步功能都不错,却被埋没了2. 够快云3. DBFen4. Seafile5. 坚果云6. DZ7. 百度云8. 1159. 迷你云10. 微云11. Dro ...

  6. A basic Windows service in C++ (CppWindowsService)

    A basic Windows service in C++ (CppWindowsService) This code sample demonstrates creating a basic Wi ...

  7. zabbix 插件使用问题

    [elk@dr-mysql01 frontend]$ ../../bin/logstash -f std02.conf Settings: Default pipeline workers: 8 Pi ...

  8. 什么时候使用NO_UNNEST

    select * from test a where object_id in (select department_id from hr.dept_1 dept where department_i ...

  9. 【转】Win8/8.1/Win7小技巧:揪出C盘空间占用的真凶

    原文网址:http://www.ithome.com/html/win8/55496.htm 不少使用Win8.Win8.1的用户不难发现,原先只占用20G大小的系统盘,随着使用时间的增加,C盘的磁盘 ...

  10. 【转】DELL戴尔N4050笔记本拆机(图文)

    原文网址:http://www.ywxydn.com/1047.html