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

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

  • 相关阅读:
    重温MVC基础入门
    重温ASP.NET WebAPI(一)初阶
    WebApi的安全性及其解决方案
    Asp.net Core + EF Core + Bootstrap搭建的MVC后台通用管理系统模板(跨平台版本)
    ASP.NET经典权限解决方案,适用于OA、CRM、ERP、HR等应用系统
    一款MVC5+EF+Bootstrap搭建的后台通用管理系统模板
    mac设置多个屏幕显示的问题
    JavaScript有这几种测试
    Script error.解决方法
    Script error.深度测试
  • 原文地址:https://www.cnblogs.com/2014acm/p/3883771.html
Copyright © 2011-2022 走看看