C++ STL 中的 set::begin() 和 set::end()
Set::begin() 函式是一個雙向迭代器,用於返回一個指向集合容器中第一個元素的迭代器。
Set::end() 函式是一個雙向迭代器,用於返回一個指向集合容器中最後一個元素的迭代器。
示例程式碼
#include<iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
set<int> s;
set<int>::iterator it;
s.insert(7);
s.insert(6);
s.insert(1);
s.insert(4);
s.insert(2);
s.insert(9);
s.insert(10);
for (auto it=s.begin(); it != s.end(); ++it)
cout << ' ' << *it;
return 0;
}輸出
1 2 4 6 7 9 10
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 語言
C++
C#
MongoDB
MySQL
Javascript
PHP