容器,迭代器,算法使用小例

  1 #include <iostream>
  2 #include <vector>
  3 #include <algorithm>
  4
  5 using std::string;
  6 using std::cin;
  7 using std::cout;
  8 using std::endl;
  9
 10 int main(){
 11
 12     std::vector< int > v;
 13     int s;
 14     std::vector<int>::iterator it;
 15     
 16     while(cin>>s)
 17         v.push_back(s);
 18         
 19     //使用排序算法
 20     sort(v.begin(),v.end());
 21     
 22     //使用迭代器
 23     for(it=v.begin();it!=v.end();it++){
 24         cout<<*it<<endl;
 25     }   
 26     
 27     return 0;
 28 } 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章