Programing/c/c++
람다 샘플 코드2
패스맨
2011. 10. 28. 17:59
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
class testclass
{
public:
testclass();
~testclass();
};
int _tmain(int argc, _TCHAR* argv[])
{
auto func = [](int n) {cout<<"number:" << n <<endl; } ;
func(333);
auto func1 = [](){return 3.14; };
float f1 = func1();
cout<<f1<<endl;
vector<int> moneys;
moneys.push_back(1000);
moneys.push_back(999);
int totalmoney = 0;
for_each(moneys.begin() , moneys.end(), [&totalmoney](int money)
{
totalmoney += money;
}
);
cout<<"totalmoney:" <<totalmoney<<endl;
return 0;
}