#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. git 撤销本地修改

    git checkout file 例如:git checkout app/views/carts/_index_m.html.erb 可以先用 git status 查看差异 然后 git chec ...

  2. Hadoop化繁为简(一)-从安装Linux到搭建集群环境

    简介与环境准备 hadoop的核心是分布式文件系统HDFS以及批处理计算MapReduce.近年,随着大数据.云计算.物联网的兴起,也极大的吸引了我的兴趣,看了网上很多文章,感觉还是云里雾里,很多不必 ...

  3. MCU PWM DAC OP Voltage Output

  4. IBDAP-CMSIS-DAP

    IBDAP-CMSIS-DAP Armstart's CMSIS-DAP firmware implementation in gcc and makefile. http://www.armstar ...

  5. 数据库数据格式化之Kettle Spoon

    前言 现在的数据库种类越来越多,数据库备份的格式也越来越复杂,所以数据格式化一直是一个老生常谈的问题.据库备份文件格式那么多,既有SQL的,也有BAK的,还有TXT的等.数据库种类也有很多,MySQL ...

  6. DELPHI实现关机,兼容全部WINDOWS系统 转

    {=================================================================================================== ...

  7. VC 中 编译 boost 1.34.1 或者 1.34.0

    c++boost正则表达式的安装方法 (cy163已成功完成实验 基于宽字节 wstring 解决 "南日" 错误 匹配"12日" expression = & ...

  8. EF Code First更新数据库时报错:provider: SQL Network Interfaces, error: 26

    在使用EF Code First更新数据库时报如下错误: 在与 SQL Server 建立连接时出现与网络相关的或特定于实例的错误.未找到或无法访问服务器.请验证实例名称是否正确并且 SQL Serv ...

  9. 委托、Lambda表达式、事件系列05,Action委托与闭包

    来看使用Action委托的一个实例: static void Main(string[] args) { int i = 0; Action a = () => i++; a(); a(); C ...

  10. linux下一个网卡配置多个IP

    转自:http://blog.csdn.net/beckdon/article/details/15815197 最常用的给网卡配置ip的命令为 #ifconfig eth0 192.168.0.1 ...