vector的大小的疑问--begin()到end()不等于大小
vector<string> sound_path;
sound_path.size() 是8
但是使用
for (vector<string>::const_iterator p=sound_path.begin();p!=sound_path.end();++p)
打印出来的却只有5个值,
大侠能否告知这会是什么问题造成的。实在是纳闷了,不会是内存操作有问题吧
具体的代码如下:
void test()
{
for(int i=0;i<100;++i)
test1();
}
void test1()
{
vector<string> sound_path;
sound_path.push_back("aaaa");
sound_path.push_back("bbbb");
test2(sound_path);
}
void test2(vector<string> & sound_path)
{
printf("%d",sound_path.size());
for (vector<string>::const_iterator p=sound_path.begin();p!=sound_path.end();++p)
sprintf(tmp,"P:%s",(*p).c_str());
}
这样的代码是否有什么隐藏的问题.