日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > c/c++ >内容正文

c/c++

c++ stl队列初始化_创建一个向量,并将其像C ++ STL中的数组一样初始化

發(fā)布時(shí)間:2025/3/11 c/c++ 21 豆豆
生活随笔 收集整理的這篇文章主要介紹了 c++ stl队列初始化_创建一个向量,并将其像C ++ STL中的数组一样初始化 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

c++ stl隊(duì)列初始化

向量是什么? (What is the vector?)

Vector is a container in C++ STL, it is used to represent array and its size can be changed.

Vector是C ++ STL中的一個(gè)容器,用于表示數(shù)組,并且其大小可以更改。

Read more: C++ STL Vector

: C ++ STL矢量

創(chuàng)建一個(gè)向量并將其初始化為數(shù)組 (Create a vector and initializing it like an array)

We can also initialize a vector like an array in C++ STL. Here, we are going to learn the same, how can we initialize a vector like an array?

我們還可以在C ++ STL中像數(shù)組一樣初始化向量。 在這里,我們將學(xué)習(xí)相同的知識(shí), 我們?nèi)绾纬跏蓟駭?shù)組這樣的向量?

Here is the syntax to create and initialize a vector like an array,

這是創(chuàng)建和初始化向量(如數(shù)組)的語(yǔ)法,

vector<type> vector_name{element1, element2, ...};

Here,

這里,

  • type – is the datatype.

    type –是數(shù)據(jù)類型。

  • vector_name – is any use defined name to the vector.

    vector_name –是向量的任何使用定義的名稱。

  • element1, element2, ... – elements to initialize a vector.

    element1,element2,... –用于初始化向量的元素。

Example to create/declare and initialize vector like an array

創(chuàng)建/聲明和初始化向量(如數(shù)組)的示例

vector::<int> v1{ 10, 20, 30, 40, 50 };

C ++ STL程序來(lái)創(chuàng)建和初始化像數(shù)組一樣的向量 (C++ STL program to create and initialize a vector like an array)

//C++ STL program to create and initialize //a vector like an array #include <iostream> #include <vector> using namespace std;int main() {//vector declaration and initialization//like an arrayvector<int> v1{ 10, 20, 30, 40, 50 };//printing the vector elements//using for each kind of loopcout << "Vector v1 elements are: ";for (int element : v1)cout << element << " ";cout << endl;//pushing the elementsv1.push_back(10);v1.push_back(20);v1.push_back(30);v1.push_back(40);v1.push_back(50);//printing the vector elements//using for each kind of loopcout << "After pushing the elements\nVector v1 elements are: ";for (int element : v1)cout << element << " ";cout << endl;return 0; }

Output

輸出量

Vector v1 elements are: 10 20 30 40 50 After pushing the elements Vector v1 elements are: 10 20 30 40 50 10 20 30 40 50

翻譯自: https://www.includehelp.com/stl/create-a-vector-and-initialize-it-like-an-arrays.aspx

c++ stl隊(duì)列初始化

總結(jié)

以上是生活随笔為你收集整理的c++ stl队列初始化_创建一个向量,并将其像C ++ STL中的数组一样初始化的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。