c++ for each

#include <iostream>
#include <vector>
#include <list>

using namespace std;

int main()
{

  vector<int> a;
  for (int k=0;k<10;k++)
  {
    a.push_back(k);
  }

  list<char> b;
  for (char c='a';c<'k';++c)
  {
    b.push_back(c);
  }

  //STL算法
  for each (int a1 in a)
  {
    cout << a1<< " ";
  }
  cout << endl;
  cout << "--------------------------------------------"<< endl;

  for each(char b1 in b)
  {
    cout << b1 << " ";
  }
  cout << endl;

  system("pause");
  return 0;
}

 

 

---------------------------------------------

0 1 2 3 4 5 6 7 8 9
--------------------------------------------
a b c d e f g h i j
请按任意键继续. . .

posted @ 2019-06-06 08:41  西北逍遥  阅读(3960)  评论(0编辑  收藏  举报