VC6中vector::insert()函数奇怪问题,高手请进!
郑大满 2011-11-15 09:12:31 在使用vector::insert()是,遇到一个奇怪的问题,以下是测试代码:
问题:Test1()函数和Test2()函数输出的结果应该是一样的,但是在VC6中测试,结果不一样;而在VC2008或VC2010里测试,结果是一样的。
难道是VC6中vector::insert函数的bug?
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
void Output( vector<char> & v )
{
for( int j=0;j<v.size();j++)
{
cout << setw(2) << v[j] << " ";
}
cout<<endl;
}
void Test1()
{
char st[]="AAAAabcdefghij";
vector<char> a(st,st+14);
Output( a );
a.insert( a.begin()+1, a.begin()+9, a.begin()+12);
Output( a );
}
void Test2()
{
char st[]="abcdefghij";
vector<char> a(st,st+10);
a.insert(a.begin(),4,'A');
Output( a );
a.insert( a.begin()+1, a.begin()+9, a.begin()+12);
Output( a );
}
int main()
{
for(int i=0; i<14; i++)
{
cout << setw(2) << i << " ";
}
cout << endl;
Test1();
cout << "-----------------------------------" << endl;
Test2();
return 0;
}