⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chapter8-14.cpp

📁 STL程序员开发指南源码
💻 CPP
字号:
//文件名:CHAPTER8-14.cpp
#include <iostream>
#include <list>
#if _MSC_VER > 1020   // if VC++ version is > 4.2
   using namespace std;  // std c++ libs implemented in std
#endif
typedef list<char >  CHARLIST;
void print_contents (CHARLIST  list, char*);
void main()
{   //create a  with  A, B, C and D
    CHARLIST  a;
    a.push_back('A');
    a.push_back('B');
    a.push_back('C');
    a.push_back('D');
    //print out the contents
    print_contents (a,"a");
    cout <<"max_size of a is " <<a.max_size() <<endl;
    cout <<"size of a is " <<a.size() <<endl;
   //let us increase the size to 10
    // and set the new elements to be 'X'
    a.resize(10,'X');
    print_contents (a,"a");
    cout <<"size of a is " <<a.size() <<endl;
    //let us resize it to 5
    a.resize(5);
    print_contents (a,"a");
    cout <<"size of a is " <<a.size() <<endl;
    cout <<"max_size of a is still " <<a.max_size() <<endl;
    }
//function to print the contents of list
void print_contents (CHARLIST  list, char *name)
{
    CHARLIST::iterator plist;
    cout <<"The contents of "<< name <<" : ";
    for(plist = list.begin(); plist != list.end(); plist++)
    { cout << *plist <<" " ;}
    cout<<endl;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -