指出下面C++代码(with STL)的错误,测测你的水平(选自GotW)
陈硕 2001-10-30 12:48:46 // Example 2: Some fun with vectors
// Difficulty: 4 / 10
vector<int> v;
v.reserve( 2 );
assert( v.capacity() == 2 );
v[0] = 1;
v[1] = 2;
for( vector<int>::iterator i = v.begin();
i < v.end(); i++ )
{
cout << *i << endl;
}
cout << v[0];
v.reserve( 100 );
assert( v.capacity() == 100 );
cout << v[0];
v[2] = 3;
v[3] = 4;
// ...
v[99] = 100;
for( vector<int>::iterator i = v.begin();
i < v.end(); i++ )
{
cout << *i << endl;
}
如果你能指出全部错误,你的C++水平一定很高喔。