首页 > 其他 > 详细

for auto

时间:2021-03-30 16:36:53      阅读:18      评论:0      收藏:0      [点我收藏+]

 

 

#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

 

for auto

原文:https://www.cnblogs.com/dream397/p/14596809.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!