首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

STl:list中的插入操作!向小弟我开炮吧

2012-09-13 
STl::list中的插入操作!向我开炮吧![codeC/C++][/code]#include vector#include list#include iostr

STl::list中的插入操作!向我开炮吧!
[code=C/C++][/code]
#include <vector>
#include <list>
#include <iostream>
using namespace std;
int main()
{vector<int> v1(10,250);
vector<int>::iterator pv;
pv=v1.begin();
list<int> l1(pv,pv+5);
list<int>::iterator pl;
for(pl=l1.begin();pl!=l1.end();pl++)
{
cout<<*pl<<'\t';
}
pl=l1.begin();
cout<<endl<<"1:"<<endl;
l1.insert(pl++,l1.begin(),l1.end());
for(pl=l1.begin();pl!=l1.end();pl++)
{
cout<<*pl<<'\t';
}
cout<<"2:"<<endl;
pl=l1.begin();
l1.insert(pl,pl++,l1.end());
for(pl=l1.begin();pl!=l1.end();pl++)
{
cout<<*pl<<'\t';
}
cout<<endl;
return 0;
}

问题描述:第二个插入操作为什么不能成功,当按下ctrl+c后会产生一个异常。
静待大牛前来!

[解决办法]
没仔细看代码,不过VS2008编译没有问题。

C/C++ code
250     250     250     250     2501:250     250     250     250     250     250     250     250     250     2502:250     250     250     250     250     250     250     250     250     250250     250     250     250     250     250     250     250     250     250Press any key to continue . . .
[解决办法]
GCC测试的结构也是一样的。

探讨

没仔细看代码,不过VS2008编译没有问题。
C/C++ code
250 250 250 250 250
1:
250 250 250 250 250 250 250 250 250 250
2:
250 250 250 250 250 250 ……

[解决办法]
探讨

能说说具体怎么回事不?我看了,但没懂><!
引用:
l1.insert(pl,pl++,l1.end());

看置顶的帖子!!

热点排行