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