码迷,mamicode.com
首页 > 编程语言 > 详细

C++中int转string与string转int

时间:2015-05-26 10:34:26      阅读:213      评论: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
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!