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