首页 > 编程语言 > 详细

C++中int转string与string转int

时间:2015-05-26 10:34:08      阅读:260      评论:0      收藏:0      [点我收藏+]
#include "stdafx.h"
#include "string"
#include "iostream"
#include "vector"
#include "sstream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    //string 转 int
    stringstream ss;
    string str;
    int i;
    ss<<"100";
    ss>>i;
    i=i+100;
    cout<<i<<endl;//输出结果200

    //int 转 string
    stringstream ssm;
    ssm<<5;
    str=ssm.str();
    str=str+"8";
    cout<<str;//输出结果58
    getchar();

    return 0;
}
#include "stdafx.h"
#include "string"
#include "iostream"
#include "vector"
#include "sstream"
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    //string 转 int
    stringstream ss;
    string str;
    int i;
    ss<<"100";
    ss>>i;
    i=i+100;
    cout<<i<<endl;//输出结果200

    //int 转 string
    stringstream ssm;
    ssm<<5;
    str=ssm.str();
    str=str+"8";
    cout<<str;//输出结果58
    getchar();

    return 0;
}

 

C++中int转string与string转int

原文:http://www.cnblogs.com/wicrecend/p/4529786.html

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