#include <iostream>
#include <set>
#include <vector> using namespace std; int main()
{
set<int> setInt;
vector<int> ivec;
for(vector<int>::size_type i = 0; i != 11; ++i)
ivec.push_back(i);
setInt.insert(ivec.begin(), ivec.end());
setInt.insert(11);
set<int>::iterator itor1 = setInt.find(9);// 这个也对,为什么const类型的键值可以用非const的迭代器?????
set<int>::const_iterator itor2 = setInt.find(10);
if(itor1 != setInt.end())
cout << *itor1 << endl;
/*
*itor1 = 12; //error:keys in a set are read-only 正如不能修改mao中元素的键部分一样,set中的键也是const,在获取迭代器后只能对其进行读操作
*/
if(itor2 != setInt.end())
cout << *itor2 << endl;
system("pause");
return 0;
}

  

 #include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map> using namespace std; void restricted_wc( vector<string> strVec, map<string, int> &wordCount )
{
// create a set of excluded words
set<string> excluded;
for ( vector<string>::iterator it = strVec.begin(); it != strVec.end(); ++it )
{
excluded.insert( *it );
} string word;
cout << " Input some words to count the words in wordCount(map) ( ctrl + z to end): "
<< endl;
cin.clear();
while ( cin >> word )
{
if ( !excluded.count( word ) )
++wordCount[ word ];
}
} int main(int argc, char* argv[])
{
cout << " Input some words to vector<string> excluded ( ctrl + z to end): " << endl;
vector<string> excludedVec;
string excludedWord;
while ( cin >> excludedWord )
excludedVec.push_back( excludedWord ); // use restricted_wc()
map< string, int > wordCount;
restricted_wc( excludedVec, wordCount ); // show out the map:wordCount
cout << "\n\tShow out the map:wordCount: " << endl;
for ( map< string, int >::iterator it = wordCount.begin(); it != wordCount.end(); ++it )
{
cout << " The word '" << (*it).first << "' appears for " << (*it).second << " times. " << endl;
} system("pause");
return ;
}

随机推荐

  1. COGS NIOP联赛 图论相关算法总结

    最小生成树 Kruskal+ufs int ufs(int x) { return f[x] == x ? x : f[x] = ufs(f[x]); } int Kruskal() { int w ...

  2. 2015-2016 Petrozavodsk Winter Training Camp, Nizhny Novgorod SU Contest (5/9)

    2015-2016 Petrozavodsk Winter Training Camp, Nizhny Novgorod SU Contest B. Forcefield 题意 给你一维平面上n个镜子 ...

  3. 使用CefSharp在.Net程序中嵌入Chrome浏览器(八)——Cookie

    CEF中的Cookie是通过CookieManager来管理的,可以用它来设置发送的Cookie. 发送Cookie 发送Cookie的一个基本示例如下: var cookieManager = _c ...

  4. TVS二极管和稳压二极管的区别

    TVS二极管和稳压二极管的区别 TVS管超过它的耐压值后,会瞬间导通短路,反应速度在ns级, 而稳压管是稳压作用的,超过它的稳压值,只要功率不超过它的耐受值,就会稳定在它的稳压值范围内. TVS是瞬态 ...

  5. ChromeDriver启动Chrome浏览器后,地址栏只显示data;——chromeDriver版本不对

    ChromeDriver启动Chrome浏览器后,地址栏只显示data; 错误原因: chromeDriver版本不对,不同版本的chromeDriver对应不同版本的chrome浏览器 chrome ...

  6. 坐标的相对转换ClientToScreen与ScreenToClient

    假如一个有一个TEdit的实例edt_Position,edt_Position所在容器有好几层,所在的窗体为frmMain.现要弹出一个FORM,FORM的容器为frmMain,弹出的位置在edt_ ...

  7. Oracle Applications Documentation

    Oracle E-Business Suite Documentation Web Library Release 12.2+ Link Download Oracle E-Business Suit ...

  8. eclipse 中 import sun.misc.BASE64Decoder; 报错

    from://http://blog.sina.com.cn/s/blog_48964b120101ahrf.html 在android做3DES加密功能时 eclipse 中 import sun. ...

  9. Linux学习2-在阿里云服务器上部署禅道环境

    前言 以前出去面试总会被问到:测试环境怎么搭建?刚工作1-2年不会搭建测试环境还可以原谅自己,工作3-5年后如果还是对测试环境搭建一无所知,面试官会一脸的鄙视. 本篇以最简单的禅道环境搭建为例,学习下 ...

  10. java获取视频播第一帧

    FFMPEG 功能很强大,做视频必备的软件.大家可通过 http://ffmpeg.org/ 了解.Windows版本的软件,可通过 http://ffmpeg.zeranoe.com/builds/ ...