20110405-pair类型

//关联容器和顺序容器的本质区别在于:关联容器通过键(KEY)存储和读取元素,而顺序容器则通过元素在容器中的位置存储和访问元素
//
// 使用标准库Pair类型必须包含库文件utility
//
// pair包含两个数值,与容器一样,pair也是一种模版类型。但与容器不同,在创建pair对象时,必须提供两个类型值。
//
// 注意pair > ppp中两个>中间要有空格
//
// pair类型使用相当繁杂,因此,如果需要定义多个相同的pair类型对象,可考虑用typedef简化其声明
//
//
// 除了构造函数,标准库还定义了一个make_pair函数,由传递给它的两个实参生成一个新的pair对象

 

#include 
#include 
#include 
#include 
using namespace std;
using std::string;
 
void main()
{
    pair anon;
    pairint> word_count;
    pairint> >line;
 
    pair author("James","Joyce");
 
    typedef pair Author;
    Author proust("Marcel","Proust");
    Author joyce("James","Joyce");
 
    string firstbook;
    if (author.first=="James"&&author.second=="Joyce")
        firstbook="Stephen Hero";
 
    pair next_auth;
    string first,last;
    while(cin>>first>>last){
        next_auth=make_pair(first,last);
    }        
 
    while(cin>>author.first>>author.second){
        //process();
    }
 
}

你可能感兴趣的:(A10-C++,Primer读书笔记)