Код
#include <windows.h>
#include <stdio.h>
#include <vector>
//------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> vect_src, vect_rx1, vect_rx2, vect_rx3;
for( int i = 0; i < 10; i++ )
vect_src.push_back( i );
printf( "original size=%d\n", vect_src.size() );
vect_rx1.insert( vect_rx1.end(), &vect_src[ 0 ], &vect_src[ vect_src.size() - 1 ] );
vect_rx2.insert( vect_rx2.end(), &vect_src.at( 0 ), &vect_src.at( 9 ) );
vect_rx3.insert( vect_rx3.end(), vect_src.begin(), vect_src.end() );
printf( "size1=%d size2=%d size3=%d\n", vect_rx1.size(), vect_rx2.size(), vect_rx3.size() );
return 0;
}
#include <stdio.h>
#include <vector>
//------------------------------------------------------------------------------
int _tmain(int argc, _TCHAR* argv[])
{
std::vector<int> vect_src, vect_rx1, vect_rx2, vect_rx3;
for( int i = 0; i < 10; i++ )
vect_src.push_back( i );
printf( "original size=%d\n", vect_src.size() );
vect_rx1.insert( vect_rx1.end(), &vect_src[ 0 ], &vect_src[ vect_src.size() - 1 ] );
vect_rx2.insert( vect_rx2.end(), &vect_src.at( 0 ), &vect_src.at( 9 ) );
vect_rx3.insert( vect_rx3.end(), vect_src.begin(), vect_src.end() );
printf( "size1=%d size2=%d size3=%d\n", vect_rx1.size(), vect_rx2.size(), vect_rx3.size() );
return 0;
}
но почему получается 9 в первом и втором случае ?
original size=10
size1=9 size2=9 size3=10
добавить еденичку нельзя - схлопочешь out of range
P.S. через итератор варианты 1 и 2 заработали как надо, но блин почему более короткая и читаемая форма записи не работает - не понятно