正在加载图片...
Map Usage #include<map> map<string, int> Word //definition map<string, Int>. Iterator It word //accessing value it word- Word begin(; cout < it word->first <<"---''< it word->second << endl Word Hello=1; //if key exist, access its value; if not, a new key was inserted /finding key if(1 I= Word[ Hello") //dangerous, new entry may be inserted it word= Word. find( Hello) if (it word!=Word. endo) //found it int cnt=Word count("Hello); if(0=cnt //found itMap Usage #include<map> map<string, int> Word; //definition map<string, int>::iterator it_word; //accessing value it_word = Word.begin(); cout << it_word->first << “---” << it_word->second << endl; Word[“Hello”] = 1; //if key exist, access its value; if not, a new key was inserted //finding key if (1 != Word[“Hello”]) //dangerous, new entry may be inserted it_word = Word.find(“Hello”); if (it_word != Word.end()) //found it int cnt = Word.count(“Hello”); if (0 != cnt) //found it
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有