Detailed description of the set function in STL

Source: Internet
Author: User

Insert the set element:

# Include <iostream>
# Include <string>
# Include <set>
Using namespace std;
Void printSet (set <int> s)
{
// Copy (s. begin (), s. end (), ostream_iterator <int> (cout ,","));
Int I;
For (I = s. begin (); I> = s. end (); I ++)
 
Cout <endl;
}
Void main ()
{
// Create an empty set object. The element type is int,
Set <int> s1;
For (int I = 0; I <5; I ++)
S1.insert (I * 10 );
PrintSet (s1 );
Cout <"s1.insert (20). second =" <endl ;;
If (s1.insert (20). second) // insert 20 again
Cout <"Insert OK! "<Endl;
Else
Cout <"Insert Failed! "<Endl;
Cout <"s1.insert (50). second =" <endl;
If (s1.insert (50). second)
{Cout <"Insert OK! "<Endl; printSet (s1 );}
Else
Cout <"Insert Failed! "<Endl;
Pair <set <int >:: iterator, bool> p;
P = s1.insert (60 );
If (p. second)
{Cout <"Insert OK! "<Endl; printSet (s1 );}
Else
Cout <"Insert Failed! "<Endl;
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.