STL Collection set--First Dictionary of Andy (pick)

Source: Internet
Author: User
Tags uppercase letter

Set is a mathematical set--each element appears at most once, and as in sort, the custom type can also construct set, but it must also define the "less than" operator

(PS: Multiset is a collection of data that is allowed to be duplicated)

Set does not support random access and must be accessed using an iterator.

Begin () returns the iterator that points to the first element
Clear () Clears all elements
COUNT () returns the number of elements of a value
Empty () returns True (True) if the collection is empty
End () returns an iterator that points after the last element, not the last element
Erase () Delete elements in the collection
Find () returns an iterator that points to the element being found
Insert () Inserts an element into the collection
Max_size () returns the maximum limit of the elements that the collection can hold
The number of elements in the size () collection
Swap () swap two set variables

Examples

Enter a text to find all the different words (sequential alphabetical sequence), output from small to large in dictionary order, Word is not case-sensitive

Sample Example

Code

#include <iostream>#include<string>#include<Set>#include<sstream>using namespacestd;Set<string>dict;//CollectionintMain () {stringS,buf;  while(cin>>R) {         for(intI=0; I<s.length (); i++)            if(Isalpha (S[i])) s[i]=ToLower (S[i]); Elses[i]=' ';               StringStream SS (s); //Create a StringStream object SS that stores a copy of S             while(SS&GT;&GT;BUF) Dict.insert (BUF);//Save converted lowercase words into the collection    }     for(Set<string>::iterator It=dict.begin (); It!=dict.end (); ++it) cout<<*it<<Endl; //System ("pause");    return 0;}

Isalpha () determines if the character ch is an English letter, and if it is lowercase, returns 2, or 1 if it is an uppercase letter. Returns 0 if it is not a letter.

ToLower () converts characters to lowercase letters, non-alphabetic characters do not make processing

STL Collection set--First Dictionary of Andy (pick)

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.