C++中int转string与string转int

#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;
}
posted @ 2015-05-26 09:49  Wicrecend  阅读(163)  评论(0编辑  收藏  举报
TOP