C++ assign()函数的简单使用

#include
#include
#include
#include


using namespace std;




void assign_use()
{
char *ac[] = {"liu","yu","dong","xiao","fa","hua"};
int acNum = sizeof(ac)/sizeof(*ac);
list clist(ac, ac+acNum);
list ::iterator list_ter= clist.begin();
vector svec;
svec.clear();
vector::iterator ster = svec.begin();


svec.assign(clist.begin(), clist.end());
if (!svec.empty())
{
for (ster=svec.begin();ster!=svec.end(); ster++)
{
cout<< *ster< }
}
else
{
cout<<"svce is empty;"< while (list_ter!=clist.end())
{
cout<<*list_ter++<

}
}
}


void back_use()
{
vector svec;
vector ::iterator iter1;
vector ::iterator iter2;
for (int i=0;i<10;i++)
{
svec.push_back(i);
}
iter1 = svec.begin();    //返回的是迭代器开始位置
iter2 = svec.end()-1;    //返回迭代器最后的一个元素的下一个位置,所以要减去一
cout< cout< cout<<"iter1= "<<*iter1< cout<<"iter2= "<<*iter2<

}


int main(void)
{
/****************************************************** 
说明:assign()的用法;
作用:以迭代器start和end指示的范围为list赋值;
******************************************************/
assign_use();


back_use();






system("pause");
return 0;
}

你可能感兴趣的:(C++ assign()函数的简单使用)