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