当前位置: 首页>>代码示例>>C++>>正文


C++ Author::insert方法代码示例

本文整理汇总了C++中Author::insert方法的典型用法代码示例。如果您正苦于以下问题:C++ Author::insert方法的具体用法?C++ Author::insert怎么用?C++ Author::insert使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Author的用法示例。


在下文中一共展示了Author::insert方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: main

int main()
{
    Author authors;
    string authorName, authorWork, searchItem;
    // Preparation Work : cin some items
    do{
        cout << "Enter author name(Ctrl+Z to quit):" << endl;
        cin >> authorName;
        if ( ! cin )
            break;
        cout << "Enter author's work (Ctrl+Z to quit)" << endl;
        while ( cin >> authorWork )
            authors.insert( make_pair(authorName,authorWork) );
        cin.clear();
    } while ( cin );
    cin.clear();

    // Search and Erasure work
    cout << "Who is the author that you want to erase? :" << endl;
    cin >> searchItem;
    Author::iterator iter;

    // for Exercise 10.26
    iter = authors.find( searchItem );
    if ( iter != authors.end() )
        authors.erase( searchItem );
    else
        cout << "No match found!" << endl;
    // end for Exercise 10.26

    // for Exercise 10.27
    pair<AuIter, AuIter> pos = authors.equal_range( searchItem );
    if ( pos.first != pos.second )
        authors.erase( pos.first, pos.second );
     else
        cout << "No match found!" << endl;
    // end for Exercise 10.27

    // Final stored items Output
    cout << "author\t\twork:" << endl;
    for( iter = authors.begin(); iter != authors.end(); iter++)
        cout << iter->first << "\t\t" << iter->second << endl;

    // for Exercise 10.28
    iter = authors.begin();
    if ( iter == authors.end() )
    {
        cout << "Empty multimap!" << endl;
        return 0;
    }
    string currAuthor, preAuthor;
    do{
        currAuthor = iter->first;
        if ( preAuthor.empty() || currAuthor[0] != preAuthor[0] )
            cout << "Author Names Begining with '" << currAuthor[0] << "' :" <<endl;
        cout << currAuthor;
        for (pos = authors.equal_range(currAuthor); pos.first != pos.second; pos.first++)
            cout << ", " << pos.first->second;
        cout << endl;
        iter = pos.second;
        preAuthor = currAuthor;
    } while ( iter != authors.end() );
    // end for Exercise 10.28

    return 0;
}
开发者ID:jakejiangjn,项目名称:CppPrimer4Ed,代码行数:66,代码来源:Ch10_Sec5_multimapEx.cpp


注:本文中的Author::insert方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。