vector中的front和back函数的赋值操作
程序员文章站
2022-03-23 09:19:24
...
#include <vector>
#include <iostream>
int main() {
using namespace std;
vector <int> v1;
v1.push_back(10);
v1.push_back(11);
int& i = v1.back(); //返回v1中的最后一个元素
const int& ii = v1.front(); //返回第一个元素
cout << "The last integer of v1 is " << i << endl;
i--;
cout << "The next-to-last integer of v1 is " << ii << endl;
}
front函数为返回向量中的第一个元素,back返回最后一个函数。
上一篇: Linux修改网卡窗口大小方法,不使用sysctl.conf
下一篇: vector的常见用法
推荐阅读
-
C++中的赋值操作符重载和拷贝构造函数
-
jquery操作iframe中的元素和js函数_html/css_WEB-ITnose
-
C++在单继承、多继承、虚继承时,构造函数、复制构造函数、赋值操作符、析构函数的执行顺序和执行内容...
-
jquery操作iframe中的元素和js函数_html/css_WEB-ITnose
-
JavaScript中的函数的两种定义方式和函数变量赋值_基础知识
-
C++中的赋值操作符重载和拷贝构造函数
-
闭包及访问量属性和类与对象解构赋值以及js中对html中的dom操作(时间有点紧,没全理解透,需回头整理)
-
JavaScript中的函数的两种定义方式和函数变量赋值_基础知识
-
闭包及访问量属性和类与对象解构赋值以及js中对html中的dom操作(时间有点紧,没全理解透,需回头整理)
-
C++STL的vector中front(),back(),begin(),end()的用法