zoukankan      html  css  js  c++  java
  • for auto

    #include <iostream>
    #include<string>
    #include<sstream>
    #include<vector>
    using namespace std;
    #define MAX_NUM 1000
    
    int string_to_num(string & str)
    {
       int num;
       stringstream ss(str);
       ss >> num;return num;
    }
    
    
    int main() {
        vector<int> arr;
        vector<int> num;
        string input;
        getline(cin,input,',');
        cout << "the input is " << input <<endl;;
        stringstream ss(input);
        string tmp;
        while(getline(ss,tmp,','))
        {
            arr.push_back(string_to_num(tmp));
        }
         for (auto s : arr) cout << s << endl;
    }
    root@ubuntu:~/c++# ./obj 
    1,2,3
    the input is 1
    1
    #include <iostream>
    #include<string>
    #include<sstream>
    #include<vector>
    using namespace std;
    #define MAX_NUM 1000
    
    int string_to_num(string & str)
    {
       int num;
       stringstream ss(str);
       ss >> num;
       return num;
    }
    
    
    int main() {
        vector<int> arr;
        vector<int> num;
        string input;
        //getline(cin,input,'');
        cin >> input;
        cout << "the input is " << input <<endl;;
        stringstream ss(input);
        string tmp;
        while(getline(ss,tmp,','))
        {
            arr.push_back(string_to_num(tmp));
        }
        for (auto s : arr) cout << s << endl;
    
    }
    root@ubuntu:~/c++#  g++ -std=c++11 obj.cpp  -o obj
    root@ubuntu:~/c++# ./obj 
    1,3,5,6,9
    the input is 1,3,5,6,9
    1
    3
    5
    6
    9

    引用

    include <iostream>
    #include<string>
    #include<sstream>
    #include<vector>
    using namespace std;
    #define MAX_NUM 1000
    
    int string_to_num(string & str)
    {
       int num;
       stringstream ss(str);
       ss >> num;
       return num;
    }
    
    
    int main() {
        vector<int> arr;
        vector<int> num;
        string input;
        //getline(cin,input,'');
        cin >> input;
        cout << "the input is " << input <<endl;;
        stringstream ss(input);
        string tmp;
        while(getline(ss,tmp,','))
        {
            arr.push_back(string_to_num(tmp));
        }
        for (auto & s : arr) cout << s << endl;
    
    }
    root@ubuntu:~/c++# ./obj
    1,2,3,4
    the input is 1,2,3,4
    1
    2
    3
    4
  • 相关阅读:
    CSS font-family 字体名称一览表
    jQuery动态追加移除CSS样式
    Java中super关键字的作用与用法
    I Have a Dream(我有一个梦想)
    再读《诫子书》
    世间谤我、欺我、辱我、笑我,为之奈何?
    英语句型:我除了音乐一无所能
    H5 iphoneX适配方案
    对象序列化成字符串,拼接在请求url后面
    React 60s倒计时
  • 原文地址:https://www.cnblogs.com/dream397/p/14596809.html
Copyright © 2011-2022 走看看