📄 list7-8.cpp
字号:
// 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -