c++ stl隊列初始化_創建一個向量,并將其像C ++ STL中的數組一樣初始化

c++ stl隊列初始化

向量是什么? (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中的一個容器,用于表示數組,并且其大小可以更改。

Read more: C++ STL Vector

: C ++ STL矢量

創建一個向量并將其初始化為數組 (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中像數組一樣初始化向量。 在這里,我們將學習相同的知識, 我們如何初始化像數組這樣的向量?

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

這是創建和初始化向量(如數組)的語法,

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

Here,

這里,

  • type – is the datatype.

    type –是數據類型。

  • 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

創建/聲明和初始化向量(如數組)的示例

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

C ++ STL程序來創建和初始化像數組一樣的向量 (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 array
vector<int> v1{ 10, 20, 30, 40, 50 };
//printing the vector elements
//using for each kind of loop
cout << "Vector v1 elements are: ";
for (int element : v1)
cout << element << " ";
cout << endl;
//pushing the elements
v1.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 loop
cout << "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隊列初始化

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/542286.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/542286.shtml
英文地址,請注明出處:http://en.pswp.cn/news/542286.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

計算機無法上無線網絡連接到internet,電腦連接不上無線網絡,教您怎么解決電腦連接不上無線網絡...

小編家的那位筆記本姐姐之前可能是受委屈了&#xff0c;一個一個的電腦問題丟出來給我解決。之前有段時間總是出現電腦連接不上無線網絡的問題&#xff0c;弄得那短時間天天都在想辦法是解決。現在&#xff0c;我就要將這種解決方法分享給你們&#xff0c;讓你們在遇到這個問題…

格蘭杰因果關系檢驗_混頻(mixed frequency)數據的格蘭杰因果(Grange causality)檢驗及其Matlab實現...

格蘭杰和格蘭杰因果網絡搜到的Grange大神標準照格蘭杰1934年9月出生于英國威爾士的斯旺西&#xff0c;早期就讀于諾丁漢大學&#xff0c;接受當時英國第一個經濟學數學雙學位教育&#xff0c;1955年留校任教&#xff0c;1957年在天文學雜志上他發表了第一篇論文&#xff1a;“關…

C#Convert.ToInt32(byte)方法-將字節值轉換為int

C&#xff03;Convert.ToInt32(byte)方法 (C# Convert.ToInt32(byte) Method) Convert.ToInt32(byte) Method is used to convert a specific byte value to its equivalent integer (int 32 signed number). Convert.ToInt32(byte)方法用于將特定的字節值轉換為其等效的整數(i…

后臺窗口截圖_萬人擁捧的截圖軟件來啦!讓你的工作效率提升不止一倍!

文章來自微信公眾號&#xff1a;小七有料直接進入正題&#xff0c;今天不野給大家分享兩款截圖軟件——Snipaste和FastStone Capture&#xff0c;前者與其說是一個截圖軟件&#xff0c;我更愿意稱之為貼圖軟件。兩者都在工作中很大程度提高了我的效率&#xff0c;也簡便化了我很…

ibm nvidia 超級計算機,IBM,Nvidia和美國能源部組成一個超級計算機超級團隊

CNET技術信息網7月15日國際報道: IBM將與Nvidia和美國能源部合作建立兩個新的杰出超級計算機中心. 這項合作的工作主要集中在兩個方面&#xff0c;一個是確保應用程序可以充分利用超級計算機的強大性能&#xff0c;另一個是收集開發人員&#xff0c;工程師和科學家的反饋.這兩個…

C#Convert.ToInt32(char)方法-將char值轉換為int

C&#xff03;Convert.ToInt32(char)方法 (C# Convert.ToInt32(char) Method) Convert.ToInt32(char) Method is used to convert a specific char value to its equivalent integer (int 32 signed number) (It can also be known as ASCII value). Convert.ToInt32(char)方法…

華為p40論壇_華為高端旗艦繼續發力!麒麟990 5G+超感知三攝,256GB降價799元

小米10、一加8&#xff0c;vivo NEX3S等高性能旗艦產品現已在市場上發售。其中&#xff0c;5G旗艦華為P40也在銷售團隊中&#xff0c;并且最近成為最受歡迎的旗艦產品。由于華為P40高端版從799元跌至4189元&#xff0c;消費者可以以不到800元的價格購買低價高性能旗艦產品&…

計算機基礎.doc,大學生計算機基礎.doc

WORD格式 整理分享范文范例 參考指導電子計算機的誕生1計算機的發展經歷了4個時代&#xff0c;各個時代劃分的原則是根據( )。A、計算機所采用的電子器件B、計算機的運算速度C、程序設計語言D、計算機的存儲量正確答案&#xff1a;A?2世界上第一臺電子計算機誕生于( )年。A、1…

移動端類似IOS的滾動年月控件(需要jQuery和iScroll)

http://www.cnblogs.com/ccblogs/p/5260949.html 一. 效果圖 二. 功能介紹 支持滾動和點擊選擇年月。&#xff08;目前只支持設置年月的最大最小值&#xff0c;不支持整體的最大最小值&#xff09; 三. 代碼 1. 在你的html中添加如下代碼&#xff1a; 直接加載<body>里面…

css 橫向滾動隱藏滾動條_使用CSS滾動時如何隱藏滾動條?

css 橫向滾動隱藏滾動條Introduction: 介紹&#xff1a; It is always nice to have a responsive website or web page, to create such websites or web pages we have to make use of our developing skills to a great extent to bring about the functionality as well a…

DrawerLayout側滑詳解

前面我們說了自定義側滑菜單&#xff0c;也說了SlidingMenu的使用&#xff0c;這一節我們再來說下DrawerLayout。DrawerLayout是Support Library包中實現了側滑菜單效果的控件&#xff0c;可以說DrawerLayout是因為第三方控件如SlidingMenu等出現之后&#xff0c;google借鑒而出…

華為筆記本計算機在哪,新一代華為MateBook 的機會在哪里?

2017年5月23日 在德國柏林&#xff0c;華為正式面向全球消費者發布了MateBook系列新品——13英寸靈動商務筆記本MateBook X、12英寸時尚二合一筆記本MateBook E及15.6英寸商務影音筆記本MateBook D。今天筆記本市場似乎是一個比較穩定的市場&#xff0c;筆記本的銷量增長不快&a…

python 字符串 變量_檢查變量是否為字符串的Python程序

python 字符串 變量Python | 檢查變量是否為字符串 (Python | Check if a variable is a string) To check whether a defined variable is a string type or not, we can use two functions which are Python library functions, 要檢查定義的變量是否為字符串類型&#xff0c…

mysql shell

mysql 查詢10分鐘以內的數據:select *from t_agent where int_last_login>CURRENT_TIMESTAMP - INTERVAL 10 MINUTE; mysql關聯多表進行update更新操作UPDATE TrackINNER JOIN MVON Track.trkidMV.mvidSET Track.is_showMV.is_showWHERE trkid<6等同于UPDATE Track,MVSET…

kaggle計算機視覺比賽技巧,9. 計算機視覺 - 9.12. 實戰Kaggle比賽:圖像分類(CIFAR-10) - 《動手學深度學習》 - 書棧網 · BookStack...

9.12. 實戰Kaggle比賽&#xff1a;圖像分類(CIFAR-10)到目前為止&#xff0c;我們一直在用Gluon的data包直接獲取NDArray格式的圖像數據集。然而&#xff0c;實際中的圖像數據集往往是以圖像文件的形式存在的。在本節中&#xff0c;我們將從原始的圖像文件開始&#xff0c;一步…

qthread中獲取當前優先級_Linux中強大的top命令

top命令算是最直觀、好用的查看服務器負載的命令了。它實時動態刷新顯示服務器狀態信息&#xff0c;且可以通過交互式命令自定義顯示內容&#xff0c;非常強大。在終端中輸入top&#xff0c;回車后會顯示如下內容&#xff1a;top - 21:48:39 up 8:57, 2 users, load average: 0…

JavaScript中帶示例的String repeat()方法

JavaScript | 字符串repeat()方法 (JavaScript | String repeat() Method) The String.repeat() method in JavaScript is used to generate a string by repeating the calling string n number of times. n can be any integer from o to any possible number in JavaScript.…

Python生成驗證碼

#!/usr/bin/env python #coding:utf8 import random #方法1&#xff1a; str_codezxcvbnmasdfghjklqwertyuiopZXCVBNMASDFGHJKLQWERTYUIOP0123456789new_codefor i in range(4):   new_coderandom.choice(str_code)print new_code #方法2&#xff1a; new_code[]def str_code…

snmp 獲得硬件信息_計算機網絡基礎課程—簡單網絡管理協議(SNMP)

簡單網絡管理協議(Simple Network Management Protocol)?除了提供網絡層服務的協議和使用那些服務的應用程序&#xff0c;因特網還需要運行一些讓管理員進行設備管理、調試問題、控制路由、監測機器狀態的軟件。這種行為稱為網絡管理。??隨著網絡技術的飛速發展&#xff0c;…

僵尸毀滅工程 服務器已停止運行,《僵尸毀滅工程》steam is not enabled錯誤解決方法...

Steam 上面的 Project Zomboid 因為帶有 VAC 所以建服開服需要 Steam服務器認證&#xff0c;這也是出現 steam is not enabled 錯誤主要原因&#xff0c;也是無法和普通零售正版所建的服務器聯機的罪魁禍首。分兩種情況(下面 Project Zomboid 均簡稱PZ)&#xff1a;1、steam版P…