从www.CppReference.com打包的C++参考手册

源代码在线查看: end.html

软件大小: 840 K
上传用户: dingjuan_01
关键词: CppReference www com 参考手册
下载地址: 免注册下载 普通下载 VIP

相关代码

																				  				  "HTML Tidy for Linux/x86 (vers 1 September 2005), see www.w3.org">								  end				  																				  				  				  								  				    cppreference.com > 				    "index.html">C++ Vectors > end				  								  				    end				  								  				    Syntax:				  				  				  #include <vector>				  iterator end();				  const_iterator end() const;												  The end() function returns an iterator just past the end of the				  vector.								  Note that before you can access the last element of the vector				  using an iterator that you get from a call to end(), you'll have				  to decrement the iterator first.  This is because end() doesn't				  point to the end of the vector; it points just past the end				  of the vector.  								  For example, in the following code, the first "cout" statement				  will display garbage, whereas the second statement will actually				  display the last element of the vector:								  				  vector<int> v1;				  v1.push_back( 0 );				  v1.push_back( 1 );				  v1.push_back( 2 );				  v1.push_back( 3 );								  int bad_val = *(v1.end());				  cout << "bad_val is " << bad_val << endl;								  int good_val = *(v1.end() - 1);				  cout << "good_val is " << good_val << endl;												  The next example shows how begin() and				  end() can be used to iterate through all of the members of a				  vector:  vector<int> v1( 5, 789				  ); vector<int>::iterator it; for( it = v1.begin(); it !=				  v1.end(); it++ ) { cout << *it << endl; } 								  The iterator is initialized with a call to 				  "begin.html">begin(). After the body of the loop has been				  executed, the iterator is incremented and tested to see if it is				  equal to the result of calling end(). Since end() returns an iterator				  pointing to an element just after the last element of the vector, the				  loop will only stop once all of the elements of the vector have been				  displayed.								  end() runs in constant time.								  				    Related topics:				  								  				    begin				    rbegin				    rend				  				  				  				  												  				  											

相关资源