mingw不错,最新的已经可以支持C++11的 auto关键词和lambda表达式,编程的快乐多了起来
- // test_lambda.cpp : Defines the entry point for the console application.
- //
- //#include "stdafx.h"
- // even_lambda.cpp
- // compile with: /EHsc
- #include <algorithm>
- #include <iostream>
- #include <vector>
- using namespace std;
- struct tt
- {
- int a;
- int b;
- };
- void test_auto()
- {
- tt vv;
- auto ss = vv;
- printf("%d\n", sizeof(ss));
- }
- int main()
- {
- test_auto();
- // Create a vector object that contains 10 elements.
- vector<int> v;
- for (int i = 0; i < 10; ++i)
- {
- v.push_back(i);
- }
- // Count the number of even numbers in the vector by
- // using the for_each function and a lambda expression.
- int evenCount = 0;
- for_each(v.begin(), v.end(), [&evenCount] (int n) {
- cout << n;
- if (n % 2 == 0)
- {
- cout << " is even " << endl;
- // Increment the counter.
- evenCount++;
- }
- else
- {
- cout << " is odd " << endl;
- }
- });
- // Print the count of even numbers to the console.
- cout << "There are " << evenCount
- << " even numbers in the vector." << endl;
- }
|