zoukankan      html  css  js  c++  java
  • c++的字符串流

     整型数据

    #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;
    }
    View Code

    #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   导入到 输入到   中 

                         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;
    }
    View Code

    #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;
    }

    *************************************************************************************************************************************

  • 相关阅读:
    6 【程序6 最大公约数和最小公倍数】
    5 【程序5 判断分数等级】
    4 【程序4 分解质因数】
    3 【程序3 水仙花数】
    2【程序2 输出素数】
    1 【程序1 不死神兔】
    终极解决傻X阿里钱盾新手开店及老卖家复核身份证照片模糊无法对焦问题
    struct和typedef struct彻底明白了
    CentOS 6.5 编译安装 LNMP环境
    Another MySQL daemon already running with the same unix socket
  • 原文地址:https://www.cnblogs.com/2014acm/p/3883771.html
Copyright © 2011-2022 走看看