博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
stl vector 函数_vector :: capacity()函数以及C ++ STL中的示例
阅读量:2537 次
发布时间:2019-05-11

本文共 1677 字,大约阅读时间需要 5 分钟。

stl vector 函数

C ++ vector :: capacity()函数 (C++ vector::capacity() function)

vector::capacity() is a library function of "vector" header, it is used to find the capacity of a vector, it returns the storage space currently allocated to the vector.

vector :: capacity()“ vector”头文件的库函数,用于查找向量的容量,它返回当前分配给该向量的存储空间。

Note: To use vector, include <vector> header.

注意:要使用向量,请包含<vector>标头。

Syntax of vector::capacity() function

vector :: capacity()函数的语法

vector::capacity();

Parameter(s): void – It accepts nothing as a parameter.

参数: void –不接受任何参数。

Return value: size_type – It returns capacity i.e. storage space of a vector.

返回值: size_type –返回容量,即向量的存储空间。

Example:

例:

Input:    vector
vector1{ 1, 2, 3, 4, 5 }; Function call: cout << vector1.capacity(); Output: 8

C ++程序演示vector :: capacity()函数的示例 (C++ program to demonstrate example of vector::capacity() function)

//C++ STL program to demonstrate example of//vector::capacity() function#include 
#include
using namespace std;int main(){
vector
v1; //printing the size & capacity of the vector cout << "Total number of elements: " << v1.size() << endl; cout << "Storage space: " << v1.capacity() << endl; //pushing elements v1.push_back(10); v1.push_back(20); v1.push_back(30); v1.push_back(40); v1.push_back(50); //printing the size & capacity of the vector cout << "Total number of elements: " << v1.size() << endl; cout << "Storage space: " << v1.capacity() << endl; return 0;}

Output

输出量

Total number of elements: 0Storage space: 0Total number of elements: 5Storage space: 8

Reference:

参考:

翻译自:

stl vector 函数

转载地址:http://rpvzd.baihongyu.com/

你可能感兴趣的文章
java基础之集合:List Set Map的概述以及使用场景
查看>>
Python 线程 进程 协程
查看>>
骨牌覆盖问题
查看>>
iOS语言中的KVO机制
查看>>
excel第一次打开报错 向程序发送命令时出错 多种解决办法含终极解决方法
查看>>
响应式web设计之CSS3 Media Queries
查看>>
实验三
查看>>
机器码和字节码
查看>>
环形菜单的实现
查看>>
Python 函数参数 传引用还是传值
查看>>
【解决Chrome浏览器和IE浏览器上传附件兼容的问题 -- Chrome关闭flash后,uploadify插件不可用的解决办法】...
查看>>
34 帧动画
查看>>
二次剩余及欧拉准则
查看>>
Centos 7 Mysql 最大连接数超了问题解决
查看>>
thymeleaf 自定义标签
查看>>
关于WordCount的作业
查看>>
C6748和音频ADC连接时候的TDM以及I2S格式问题
查看>>
UIView的layoutSubviews,initWithFrame,initWithCoder方法
查看>>
STM32+IAP方案 实现网络升级应用固件
查看>>
用74HC165读8个按键状态
查看>>