A finishing touch

map Traversal of data , There are also 3 Methods

* Apply forward iterator mode
* Apply backward iterator mode
* Apply array mode
two map Application practice of reverse iterator

1 code
#include <map> #include <string> #include <iostream> using namespace std; int
main(){ map<int,string> mapStudent; mapStudent[1] = "student_one";
mapStudent[2] = "student_two"; mapStudent[3] = "student_three"; map<int,
string>::reverse_iterator iter; for(iter = mapStudent.rbegin(); iter !=
mapStudent.rend(); iter++){ cout<<iter->first<<" "<<iter->second<<endl; }
return 0; }
2 function
[root@localhost charpter03]# g++ 0323.cpp -o 0323 [root@localhost charpter03]#
./0323 3 student_three 2 student_two 1 student_one
3 explain

iter Is a reverse iterator reverse_iterator, It needs rbegin() and rend() Method indicates the start and end positions of the reverse traversal . be careful , Forward traversal is generally from begin() reach end() ergodic , Reverse traversal is from ebegin() reach rend()

3. Traverse in array mode map

1 code
#include<map> #include<string> #include<iostream> using namespace std; int
main(){ map<int,string> mapStudent; mapStudent[1] = "student_one";
mapStudent[2] = "student_two"; mapStudent[3] = "student_three"; int iSize =
mapStudent.size(); for(int i = 1; i <= iSize; i++){ cout<<i<<"
"<<mapStudent[i]<<endl; } return 0; }
2 function
[root@localhost charpter03]# g++ 0324.cpp -o 0324 [root@localhost charpter03]#
./0324 1 student_one 2 student_two 3 student_three
3 explain

use size() Method to determine the current map How many elements are there in . Access with numbers vector Hour , Subscript is from 0-(size-1), And digital access map, But from 1~size, This is different .

Technology
©2019-2020 Toolsou All rights reserved,
Solve in servlet The Chinese output in is a question mark C String function and character function in language MySQL management 35 A small coup optimization Java performance —— Concise article Seven sorting algorithms (java code ) use Ansible Batch deployment SSH Password free login to remote host according to excel generate create Build table SQL sentence Spring Source code series ( sixteen )Spring merge BeanDefinition Principle of Virtual machine installation Linux course What are the common exception classes ?