#include<iostream>
using namespace std;
#include<vector>
#include<functional>
#include<algorithm>
//函数原型
//template<class T> bool logical_and<T> 逻辑与
//template<class T> bool logical_or<T> 逻辑或
//template<class T> bool logical_not<T> 逻辑非
void test0601()
{
vector<bool> v;
v.push_back(true);
v.push_back(false);
v.push_back(true);
v.push_back(false);
for (vector<bool>::iterator it = v.begin(); it != v.end(); it++)
{
cout << (*it) << " ";
}
cout << endl;
//利用逻辑非操作将容器v搬运到容器v2中,并执行取反操作
vector<bool> v2;
v2.resize(v.size());//先指定大小,再进行搬运
transform(v.begin(), v.end(), v2.begin(), logical_not<bool>());//搬运的同时做取反操作
for (vector<bool>::iterator it = v2.begin(); it != v2.end(); it++)
{
cout << (*it) << " ";
}
cout << endl;
}
int main()
{
test0601();
system("pause");
return 0;
}
网友评论