C++Primer 第9章-顺序容器-课后习题答案

}

// show

cout << \ After erase, the elements of iVec are:\ << endl; for ( vector::iterator it = iVec.begin(); it != iVec.end(); ++it ) cout << *it << \;

cout << \ After erase, the elements of iLst are:\ << endl; for ( list::iterator it = iLst.begin(); it != iLst.end(); ++it ) cout << *it << \; cout << endl; system(\); return 0;

27.编写程序处理一个string类型的list容器。在该容器中寻找一个特殊值,如果找到,则将它删除掉。用deque容器重写上述程序。

// 11.15_9.27_StringList_Find_Earse.cpp : 定义控制台应用程序的入口点。 //

#include \#include #include #include #include using namespace std;

int _tmain(int argc, _TCHAR* argv[]) { string strSerVal(\); string strArr[] = { \, \, \ }; list strLst( strArr, strArr + 3 ); list::iterator Lit = find( strLst.begin(), strLst.end(), strSerVal ); if ( Lit != strLst.end() ) {

}

cout << \ << endl; strLst.erase( Lit ); }

system(\); return 0;

用deque重写以上程序: string strSerVal(\); string strArr[] = { \, \, \ }; deque strDeq( strArr, strArr + 3 ); deque::iterator Dit = find( strDeq.begin(), strDeq.end(), strSerVal ); if ( Dit != strDeq.end() ) { cout << \ << endl; strDeq.erase( Dit ); }

28.编写一个程序将一个list容器的所有元素赋值给一个vector容器,其中list容器中存储的是指向C风格字符串的char*指针,而vector容器的元素则是string类型。 // 11.15_9.28_assignListToVector.cpp : 定义控制台应用程序的入口点。 //

#include \#include #include #include #include using namespace std; int _tmain(int argc, _TCHAR* argv[]) {

>>闂備浇顕х换鎺楀磻閻愯娲冀椤愶綆娼熼梺纭呮彧缁犳垹绮堥崒鐐寸厪濠电姴绻樺顕€鏌f惔顖涘<<
12@gma联系客服:779662525#qq.com(#替换为@) 苏ICP备20003344号-4