您的位置:首页 > 其它

getchar()输入不定长数组,getline输入字符串,int和string的相互转换

2017-09-02 21:17 886 查看
#include<iostream>
#include<map>
#include<algorithm>
#include<string>
#include<vector>
#include<sstream>
using namespace std;
void main()
{
vector<int> a;
int temp;
while (1)
{
cin >> temp;
a.push_back(temp);
if (getchar() == '\n')
break;
cout << a.size() << endl;
}
string s; getline(cin, s);
cout << s << endl; stringstream ss;
ss << s; int ab = NULL; ss >> ab;
cout << ab << endl;
int p = 9;
ss << p;
ss >> s;
cout << p << endl;
}



                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐