list7-8.cpp
来自「这是关于VC++中的STL容器的资料,包括了STL容器各个类之间关系以及类的说明」· C++ 代码 · 共 41 行
CPP
41 行
// Listing 7.8
// This program demonstrates how the size(), capacity()
// and max_size() are used. It also demonstrates how
// a container can be constructed from another container
// using the constructor or the insert() methods
#include <iostream>
#include <vector>
#include <list>
//using namespace std;
void main(void)
{
vector<int> X;
vector<int> Y;
X.push_back(1);
Y.push_back(1);
Y.push_back(3);
Y.push_back(5);
Y.push_back(7);
cout << "X size " << X.size() << endl;
cout << "X capacity " << X.capacity() << endl;
cout << "X max size " << X.max_size() << endl;
X.insert(X.begin(),Y.begin(),Y.end());
cout << "X size " << X.size() << endl;
cout << "X capacity " << X.capacity() << endl;
cout << "X max size " << X.max_size() << endl;
cout << "Y size " << Y.size() << endl;
cout << "Y capacity " << Y.capacity() << endl;
cout << "Y max size " << Y.max_size() << endl;
vector<int> Z(Y);
Z.insert(Z.end(),13,Y.front());
cout << "Z size " << Z.size() << endl;
cout << "Z capacity " << Z.capacity() << endl;
cout << "Z max size " << Z.max_size() << endl;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?