程序源代码
#include <iostream>
#include <array>
#include <utility>//for lambda
#include <vector>
#include <string>
#include <algorithm>//for_each
using namespace std;
int main()
{
array<double,10> array1 = {1,2,3,4,5,6,7,8,9,10};
int i = 0;
for_each(array1.begin(),array1.end(),[](double &base){
base *= base;
cout << base << " ";
});
cout << "\n";
vector<string> strVector = {"To those who care for people and mankind","this is a C++ program "};
auto print = [](string info){
cout << info << endl;
};
for_each(strVector.begin(),strVector.end(),print);
}
程序输出结果
1 4 9 16 25 36 49 64 81 100
To those who care for people and mankind
this is a C++ program