C++ forward_list 庫 - end() 函式



描述

C++ 函式std::forward_list::end()返回一個隨機訪問迭代器,該迭代器指向forward_list的最後一個元素。

宣告

以下是來自std::forward_list標頭檔案的std::forward_list::end()函式的宣告。

C++11

iterator end() noexcept;
const_iterator end() const noexcept;

引數

返回值

如果forward_list物件是常限定的,則方法返回常隨機訪問迭代器,否則返回非常隨機訪問迭代器。

異常

此成員函式從不丟擲異常。

時間複雜度

常數,即 O(1)

示例

以下示例顯示了std::forward_list::end()函式的使用。

#include <iostream>
#include <forward_list>

using namespace std;

int main(void) {
   forward_list<int> fl = {1, 2, 3, 4, 5};

   cout << "List contains following elements" << endl;

   for (auto it = fl.begin(); it != fl.end(); ++it)
      cout << *it << endl;

   return 0;
}

讓我們編譯並執行上述程式,這將產生以下結果:

List contains following elements
1
2
3
4
5
forward_list.htm
廣告

© . All rights reserved.