📄 sets.cpp
字号:
#include <iostream>
#include <set>
#include <string>
#include <iterator>
#include <algorithm>
using namespace std;
const int NUMBER_ELEMENTS = 5;
int main()
{
string strings1[NUMBER_ELEMENTS] = {"A", "B", "C", "D", "E"};
string strings2[NUMBER_ELEMENTS] = {"C", "D", "E", "F", "G"};
set<string> first_set(strings1, strings1 + NUMBER_ELEMENTS);
set<string> second_set(strings2, strings2 + NUMBER_ELEMENTS);
ostream_iterator<string, char> ostream_itr(cout, " ");
cout << "First set:" << endl;
copy(first_set.begin(), first_set.end(), ostream_itr);
cout << endl;
cout << "Second set:" << endl;
copy(second_set.begin(), second_set.end(), ostream_itr);
cout << endl;
cout << "Difference of the two sets:" << endl;
set_difference(first_set.begin(), first_set.end(), second_set.begin(),
second_set.end(), ostream_itr);
cout << endl;
cout << "Intersection of the two sets:" << endl;
set_intersection(first_set.begin(), first_set.end(), second_set.begin(),
second_set.end(), ostream_itr);
cout << endl;
cout << "Union of the two sets:" << endl;
set_union(first_set.begin(), first_set.end(), second_set.begin(),
second_set.end(), ostream_itr);
cout << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -