C + + Fundamentals (i): Data types and structures

Source: Internet
Author: User

1.map

Map<int, int> rankdict;//definition map rankdict[1] = 5;rankdict[2] = 6;//map Assignment int dictsize = Rankdict.size ();//map size cout << dictsize <<endl;map<int, Int>::iterator iter;for (iter = Rankdict.begin (); Iter!=rankdict.end (); iter++) {cout << iter->first <<endl;} Traverse Map iter = Rankdict.find (2);//Find cout <<iter->first<< ":" <<iter->second;//first as key, Second is valuerankdict.clear ();//Empty if (Rankdict.empty ()) {//Determine if NULL (True) cout << "Empty";} Rankdict.erase (ITER);//Remove the location of the specified key rankdict.erase (1);//delete the specified key//Because each map data corresponds to a node on a red-black tree, this node occupies 16 bytes when it does not save your data, A parent pointer, left and right child pointer, and an enumeration value (labeled Red-black, equivalent to the balance factor in the balanced binary tree), which is very memory-consuming.    

2.enum (enumeration)

Enum keyword{first,second,third}void func (keyword key) {       switch (key) {case First            :;            Case SECOND:;                     }   }

3. Arrays

int numbers[2];//numeric size is constant i = f ();vector<int> vecnumber (i);//can vary size array request int number[] = {2,3,4};//Direct initialization can not write length

  

C + + Fundamentals (i): Data types and structures

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.