vectcon.cpp
来自「本课程主要介绍面向对象程序设计的方法和c++语言的基本概念。以c++语言中的面向」· C++ 代码 · 共 25 行
CPP
25 行
// vectcon.cpp
// demonstrates constructors, swap(), empty(), back(), pop_back()
#include <iostream>
#include <vector>
using namespace std;
int main()
{ // an array of doubles
double arr[] = { 1.1, 2.2, 3.3, 4.4 };
vector<double> v1(arr, arr+4); // initialize vector to array
vector<double> v2(4); // empty vector of size 4
v1.swap(v2); // swap contents of v1 and v2
while( !v2.empty() ) // until vector is empty,
{
cout << v2.back() << ' '; // display the last element
v2.pop_back(); // remove the last element
} // output: 4.4 3.3 2.2 1.1
cout << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?