#include<iostream>
#include<cstdlib>
#include<vector>
#include<algorithm>
using namespace std;
//自定义函数声明
bool isOdd(int);
//主函数
int main(int argc,char * argv[])
{
//定义向量vector对象
vector<int> myVector;
//循环插入元素
for(int i=1;i<10;++i)
myVector.push_back(i);
//定义迭代器变量
vector<int>::iterator bound,it;
//partition
bound=partition(myVector.begin(),myVector.end(),isOdd);
cout<<"odd elements:";
//循环输出
for(it=myVector.begin();it!=bound;it++)
{
cout<<' '<<*it;
}
cout<<'\n'<<"even elements:";
//循环输出
for(it=bound;it!=myVector.end();it++)
{
cout<<' '<<*it;
}
cout<<'\n';
system("pause");
return 0;
}
//自定义函数
bool isOdd(int i)
{
return (i%2)==1;
}
谁能说说是怎么回事啊?
为什么for循环里的it++和++it输出结果一样?
相关分类