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

!错在哪里

2012-03-06 
求救!!!错在哪里?#pragmawarning(disable:4786)#include iostream#include string#include vector#i

求救!!!错在哪里?
#pragma   warning(disable:4786)
#include <iostream>
#include <string>
#include <vector>
#include <deque>
using   namespace   std;

void   main()
{
vector <string> vcs;
vcs.push_back( "this   is   A ");
vector <string   > ::iterator   it=vcs.begin();
int   i=9;
for(;it!=vcs.end();++it)
{
cout < < "caplity   of   vector   is   :   " < <vcs.size() < <endl;

cout < < "---> " < <*it < <endl;   //去掉此句会有一个超过vector
                                                                            //大小的循环,高手能解释一下为什么?
if(i==9)
{
vcs.push_back( "this   is   BBBBB ");
cout < < "vcs.push! " < <endl;
}
i=8;
}
}

上面的程序运行时发生错误;
但是把vector换成deque后,运行时就算没有错误了错误了,

[解决办法]
vcs.push_back( "this is BBBBB ");
这个之后 迭代器it已经失效了,你还使用自然会错误

热点排行