今天看vector的front這個函數msdn中的例子,給出的例程是這樣的:
// vector_front.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1;
v1.push_back( 10 );
v1.push_back( 11 );
int& i = v1.front( );
const int& ii = v1.front( );
cout << "The first integer of v1 is "<< i << endl;
i++;
cout << "The second integer of v1 is "<< ii << endl;
}
vector::back這個函數給出的例程如下:
// vector_back.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>
int main( )
{
using namespace std;
vector <int> v1;
v1.push_back( 10 );
v1.push_back( 11 );
int& i = v1.back( );
const int& ii = v1.front( );
cout << "The last integer of v1 is " << i << endl;
i--;
cout << "The next-to-last integer of v1 is "<< ii << endl;
}
其中front函數例程里面,兩個輸出the first integer和the second integer意思是i是v1中的第一個元素的引用,而ii是v1中第二個元素的引用?back函數例程里面,the last integer和the next-to-last integer兩句也是同樣的道理??墒莊ront應該都是v1中第一個元素的引用,只是i++;這句之后,ii引用的元素增加了1,恰好和v1中的第二個元素的值相同而已。
不知道是我的理解有問題,還是真的有問題,各位請指教。
posted on 2007-06-04 09:50
探丫頭 閱讀(1231)
評論(17) 編輯 收藏 引用 所屬分類:
編程語言——C++