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
请按任意键继续. . .


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM