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

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

  • 相关阅读:
    利用node搭建本地服务器调试代码
    WCF与WebService的区别
    图解HTTPS
    XMAL语法系列之-(2)---WPF控件继承图
    俩种分页的实现!
    设置二级域名共享一级域名Cookie和删除共享Cookie
    Jquery 操作IFrame
    sql中的常见的全局变量
    sql字段中逗号分隔字符串的判断
    sql sever 字符串函数
  • 原文地址:https://www.cnblogs.com/2014acm/p/3883771.html
Copyright © 2011-2022 走看看