main168.cpp
#include <iostream> #include <set> #include <algorithm> #include <string> #include <iterator> using namespace std; //由题知道,键值唯一,可以知道,应该用set static void output(string str) { cout<<str<<" "; } void main168() { set<string> Mat; set<string> Pat; string temp; cout<<"Mat ,plesase enter your friends name(q to quit):"; cin>>temp; while(temp!="q") { Mat.insert(Mat.begin(),temp); cout<<"\nMat ,plesase enter your friends name continue(q to quit):"; cin>>temp; } cout<<"Mat's friend list: "; for_each(Mat.begin(),Mat.end(),output); cout<<"\nNow ,Pat ,please enter your friend's name:"; cin>>temp; while(temp!="q") { Pat.insert(Pat.begin(),temp); cout<<"\nPat ,plesase enter your friends name continue(q to quit):"; cin>>temp; } cout<<"\nPat's friend list: "; for_each(Pat.begin(),Pat.end(),output); set<string> All; //transform(Mat.begin(),Mat.end(),All.begin(),[](set<string>::iterator it){return it;});// //set_union(Mat.begin(),Mat.end(),Pat.begin(),Pat.end(),All.begin());//用set_union set_union(Mat.begin(),Mat.end(),Pat.begin(),Pat.end(),insert_iterator<set<string> >(All,All.begin()));//p703 cout<<"\nAll list:"; for_each(All.begin(),All.end(),output); cin.get(); cin.get(); }
——————————————————————————————————————————————————
//写的错误或者不好的地方请多多指导,可以在下面留言或者给我发邮件,指出我的错误以及不足,以便我修改,更好的分享给大家,谢谢。
转载请注明出处:https://www.royalchen.com/
author:royalchen
Email:royalchen@royalchen.com
———————————————————————————————————————————————————