#include "stdafx.h"
#include
#include
#include
#include
using namespace std;
class box
{
public :
box(){};
~box(){
cout << "析构函数被执行" << endl;
};
public :
int id ;
int pos ;
int parents ;
};
void show3 (box* p)
{
cout << p->pos << endl;
}
int main(int argc, char* argv[])
{
vector
box * b1 = new box ;
b1->pos = 1;
b1->parents = 0;
box * b2 = new box ;
b2->pos = 2;
b2->parents = 1;
box * b3 = new box ;
b3->pos = 3;
b3->parents = 2;
v2.push_back(b1);
v2.push_back(b2);
v2.push_back(b3);
//遍历所有项
for_each(v2.begin(),v2.end(),show3);
//删除所有项
for (vector
{
delete *be;//注意be是二级指针
*be = NULL;
}
while(!v2.empty())
{v2.erase(v2.begin());}
if(v2.empty())
{
cout << "v2 is empty" << endl ;
}
if(!b1)
{
cout << b1->pos << endl ;
}
}
// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include
#include
#include
using namespace std;
void show (int p)
{
cout << p << endl;
}
int main(int argc, char* argv[])
{
vector
c1.push_back(1880);
c1.push_back(650);
c1.push_back(1120);
c1.push_back(950);
c1.push_back(1880);
for_each(c1.begin(),c1.end(),show);
//Statistics
while(!c1.empty())
{
//count
int num = count(c1.begin(),c1.end(),*(c1.begin()));
cout<<"elem:" << *(c1.begin()) << "---" << "times: "<
//erase
int tag = *c1.begin() ;
while( num )
{
for (vector
{
if(*iter == tag )
{
c1.erase(iter);
break;
}
}
num--;
}
}
//printf("Hello World!\n");
return 0;
}