我知道我在这里做的事情是非常错误的:
void Example( void )
{
// DECLARE LOCAL VARIABLES
::UINT nPosition = 5;
::UINT nLength = 5;
std::vector< ::UINT >vn_VectorA;
::UINT *an_ArrayA = new ::UINT[ nLength ];
// FILL vn_VectorA WITH DECIMAL VALUE OF "HelloWorld!!!"
// I KNOW THIS IS AN UGLY WAY OF DOING IT. BUT FOR DEMONSTRATION PURPOSES,
// I CAN CARELESS.
vn_VectorA.push_back( 72 ); // H
vn_VectorA.push_back( 101 ); // e
vn_VectorA.push_back( 108 ); // l
vn_VectorA.push_back( 108 ); // l
vn_VectorA.push_back( 111 ); // o
vn_VectorA.push_back( 87 ); // W
vn_VectorA.push_back( 111 ); // o
vn_VectorA.push_back( 114 ); // r
vn_VectorA.push_back( 108 ); // l
vn_VectorA.push_back( 100 ); // d
vn_VectorA.push_back( 33 ); // !
vn_VectorA.push_back( 33 ); // !
vn_VectorA.push_back( 33 ); // !
// Copy the desire values of vn_VectorA to an_ArrayA
for( ::UINT nCopyIndex = nPosition, nArrayAIndex = 0; nArrayAIndex != nLength; nArrayAIndex ++, nCopyIndex ++ )
{
an_ArrayA[ nArrayAIndex ] = vn_VectorA[ nCopyIndex ];
#ifdef DEBUG
std::cout << an_ArrayA[ nArrayAIndex ] << ' ';
#endif // DEBUG
}
};
这就是我用来复制 std::vector 某些值的方法:
// Copy the desire values of vn_VectorA to an_ArrayA
for( ::UINT nCopyIndex = nPosition, nArrayAIndex = 0; nArrayAIndex != nLength; nArrayAIndex ++, nCopyIndex ++ )
{
an_ArrayA[ nArrayAIndex ] = vn_VectorA[ nCopyIndex ];
#ifdef DEBUG
std::cout << an_ArrayA[ nArrayAIndex ] << ' ';
#endif // DEBUG
}
运行代码后,应打印:87 111 114 108 100
那么,我该怎么做呢???