静止的流水的学习日志
静止的流水
全部博文(210)
Windows(1)
Linux(31)
2011年(34)
2010年(121)
2009年(37)
2008年(18)
cynthia
wojiuzhu
jd_lzh
鄙人姓王
Jack_Tan
fanbiubi
猜我咯
aaccp1
chrisy52
分类: C/C++
2010-08-20 21:35:10
// test.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include<iostream>#include<fstream>#include<vector>#include<bitset>#include<string>#include<math.h>#include<map>#include<set>#define MAX 30using namespace std;int main(int argc, _TCHAR* argv[]){ pair<string,int> p1;//不提供初始化,采用值初始化 pair<string,int> p2("hit",10086);//提供初始化式 p1 = make_pair("hit",10086);//pair也是一种模板类,必须提供两个类型 cout<<p1.first<<endl;//成员是public类型的,可以直接访问 cout<<p1.second<<endl; p1.first = "hit"; cout<<unitbuf<<p1.first<<nounitbuf; cout<<endl<<p1.second<<endl; map<string,int> tel; tel["hit"] = 10086;//下标操作的时候,返回的是类型为mapped_type的左值,有就改变,没有就加进去 map<string,int>::iterator ite = tel.begin();//对迭代器解引用,返回的是类型为value_type的引用 map<string,int>::iterator end = tel.end(); while(ite!=end){ cout<<ite->first<<endl; cout<<ite->second<<endl; ++ite; } string word; map<string,int> wordCount; while(cin>>word){ if(cin.bad()){ throw runtime_error("error"); break; } if(cin.fail()){ cout<<"Error string"<<endl; cin.clear(cin.failbit); continue; } ++wordCount[word]; } pair<map<string,int>::iterator,bool> result =wordCount.insert(make_pair("tang",10086)); if(result.second){ cout<<"OK"<<endl; cout<<result.first->first<<" "<<result.first->second<<endl; } wordCount.insert(tel.begin(),tel.end()); ite = wordCount.begin(); end = wordCount.end(); while(ite!=end){ cout<<ite->first<<endl; cout<<ite->second<<endl; ++ite; } map<string,int>::size_type num = wordCount.erase("hit"); cout<<num<<endl; map<string,int>::iterator p = wordCount.begin(); wordCount.erase(p);}
上一篇:Linux系统中网络配置详解
下一篇:第九章 顺序容器
登录 注册