C++用sstream将string转化为int

#include <iostream>
#include <sstream>
using namespace std;

int main()
{
    string a;
    int b;
    stringstream c;
    cin.getline(a);
    c<<a;
    c>>b;
    cout<<b<<endl;
    cout<<b+1<<endl;
    return 0;
}

 

posted @ 2019-06-19 22:22  寂寞致幻  阅读(470)  评论(0编辑  收藏  举报