使用vc2010的c++0x特性,我们可以写出简洁有趣的代码
时间:2010-10-11 来源:千里马肝
#include "stdafx.h"
#include <algorithm>
#include <iostream>
#include <vector>
#include <iterator>
int _tmain(int argc, _TCHAR* argv[]) { std::vector<int> vec; int sz[] = {1, 7, 4, 2}; std::copy(sz, sz + 4, std::back_inserter(vec));
std::for_each(sz, sz + 4, [](int n){ std::cout << n << " "; }); std::cout << std::endl;
std::sort(vec.begin(), vec.end(), [](int x, int y) { return x < y; }); std::for_each(vec.begin(), vec.end(), [](int n){ std::cout << n << " "; });
std::cout << std::endl;
std::sort(vec.begin(), vec.end(), [](int x, int y) { return x > y; }); for (auto itor = vec.begin(); itor != vec.end(); ++itor) std::cout << *itor << " ";
return 0; }
int _tmain(int argc, _TCHAR* argv[]) { std::vector<int> vec; int sz[] = {1, 7, 4, 2}; std::copy(sz, sz + 4, std::back_inserter(vec));
std::for_each(sz, sz + 4, [](int n){ std::cout << n << " "; }); std::cout << std::endl;
std::sort(vec.begin(), vec.end(), [](int x, int y) { return x < y; }); std::for_each(vec.begin(), vec.end(), [](int n){ std::cout << n << " "; });
std::cout << std::endl;
std::sort(vec.begin(), vec.end(), [](int x, int y) { return x > y; }); for (auto itor = vec.begin(); itor != vec.end(); ++itor) std::cout << *itor << " ";
return 0; }
c++0x整合了一些boost的东西,c++终于也可以拥有script language的快捷手感了。
相关阅读 更多 +