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

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

  • 相关阅读:
    EF Code First一对一、一对多、多对多关联关系配置
    ASP.NET MVC 3.0 HTML辅助方法
    CSS常用命名
    ExtJS3.4.0系列:ExtJS下载使用
    在HTTP响应标题中隐藏ASP.NET MVC的版本
    ASP.NET MVC动作过滤器
    Sql Server系列:使用TransactSQL编程
    ExtJS3.4.0系列:Ext.Panel
    Sql Server系列:Select检索数据
    ASP.NET MVC资源文件多语言实现方式
  • 原文地址:https://www.cnblogs.com/2014acm/p/3883771.html
Copyright © 2011-2022 走看看