输出处理
接收多个数字,个数不固定,每个数字用’,‘隔开,如1,2,3,4,5,6(最后一个位置没有’,',所以不能用while(scanf(“%d,”,&x) == 1)来接收)
#include<iostream>
#include<sstream>
#include<string>
using namespace std;
int main()
{
string s;
cin>>s; // 接收"1,2,3,4,5,6"
string temp;
stringstream ss(s);
while(getline(ss,temp,',')){
// atoi((char *)temp.data());
cout<<atoi(temp.c_str())<<endl;;
//上下两个方法都可已使用
}
return 0;
}
处理多行输入输出