标签:style blog http color os strong io 数据
整型数据
#include <iostream> #include <string> #include <sstream> using namespace std; int main( ) { string s; int x; int sum; while (getline(cin, s)) { stringstream ss(s); sum=0; while (ss>>x) sum=sum+x; cout<<sum<<endl; } return 0; }
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main( )
{
string s;
int x; //整数
int sum;
while ( getline(cin, s) )
{
stringstream ss(s); //字符串流 初始化 stringstream ss=s ;
sum=0;
while (ss>>x) //ss 导入到 输入到 x 中
sum=sum+x; // sum 进行统计
cout<<sum<<endl;
}
return 0;
}
*******************************************************************************************************************************************
字符串类型
#include <iostream> #include <string> #include <sstream> using namespace std; int main( ) { string s,s2; while (getline(cin, s)) { stringstream ss(s); while (ss>>s2) cout<<s2<<endl; } return 0; }
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main( )
{
string s,s2;
while (getline(cin, s))
{
stringstream ss(s);
while (ss>>s2)
cout<<s2<<endl;
}
return 0;
}
*************************************************************************************************************************************
标签:style blog http color os strong io 数据
原文地址:http://www.cnblogs.com/2014acm/p/3883771.html