惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Blog — PlanetScale
Blog — PlanetScale
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
S
Secure Thoughts
S
Security @ Cisco Blogs
S
Security Affairs
Forbes - Security
Forbes - Security
W
WeLiveSecurity
H
Hacker News: Front Page
T
Threatpost
Google Online Security Blog
Google Online Security Blog
S
Schneier on Security
有赞技术团队
有赞技术团队
WordPress大学
WordPress大学
www.infosecurity-magazine.com
www.infosecurity-magazine.com
博客园 - Franky
腾讯CDC
IT之家
IT之家
博客园 - 聂微东
L
LINUX DO - 最新话题
罗磊的独立博客
Hacker News - Newest:
Hacker News - Newest: "LLM"
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
博客园 - 三生石上(FineUI控件)
Hacker News: Ask HN
Hacker News: Ask HN
C
CXSECURITY Database RSS Feed - CXSecurity.com
C
Cybersecurity and Infrastructure Security Agency CISA
C
CERT Recently Published Vulnerability Notes
Know Your Adversary
Know Your Adversary
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园_首页
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Cisco Talos Blog
Cisco Talos Blog
S
SegmentFault 最新的问题
酷 壳 – CoolShell
酷 壳 – CoolShell
Hugging Face - Blog
Hugging Face - Blog
L
LINUX DO - 热门话题
美团技术团队
G
GRAHAM CLULEY
T
The Exploit Database - CXSecurity.com
AI
AI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Jina AI
Jina AI
Help Net Security
Help Net Security
N
News | PayPal Newsroom
月光博客
月光博客
Spread Privacy
Spread Privacy
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
N
News and Events Feed by Topic

博客园 - 今夜太冷

GPG(GnuPG)入门 Session variables lost after the call of Response.Redirect method c++中POD类型和non-POD类型 关于c++ template的branching和Recursion的一段很好的描述 How do I remove a particular element from an array in JavaScript? Get the client's IP address in socket.io 前端 使用 crypto-js 对数据进行对称加密 C++ delegate的几种方法 MFC更换窗口图标 boost::make_function_output_iterator报错: C4996 How to copy the contents of std::vector to c-style static array,safely? std::vector push_back报错Access violation Structured Exception Handling Catch a Memory Access Violation in C++ Windows上的字符转换之CP_ACP和CP_OEMCP MFC中使用ATL报错:error C4430: missing type specifier - int assumed. Note: C++ does not support default-int C++ WINDOWS下 wchar_t *和char * 相互转化总结篇 VS2008 编译出错 fatal error C1859: unexpected precompiled header error, simply rerunning the compiler might fix this problem 解析XML出错,无法创建DOMDocument对象
Initialize a vector in C++ (5 different ways)
今夜太冷 · 2018-08-21 · via 博客园 - 今夜太冷

https://www.geeksforgeeks.org/initialize-a-vector-in-cpp-different-ways/

Following are different ways to create and initialize a vector in C++ STL

Initializing by one by one pushing values :

#include <bits/stdc++.h>

using namespace std;

int main()

{

    vector<int> vect;

    vect.push_back(10);

    vect.push_back(20);

    vect.push_back(30);

    for (int x : vect)

        cout << x << " ";

    return 0;

}

Output:

10 20 30

Specifying size and initializing all values :

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int n = 3;

    vector<int> vect(n, 10);

    for (int x : vect)

        cout << x << " ";

    return 0;

}

Output:

10 10 10

Initializing like arrays :

#include <bits/stdc++.h>

using namespace std;

int main()

{

    vector<int> vect{ 10, 20, 30 };

    for (int x : vect)

        cout << x << " ";

    return 0;

}

Output:

10 20 30

Initializing from array :

#include <bits/stdc++.h>

using namespace std;

int main()

{

    int arr[] = { 10, 20, 30 };

    int n = sizeof(arr) / sizeof(arr[0]);

    vector<int> vect(arr, arr + n);

    for (int x : vect)

        cout << x << " ";

    return 0;

}

Output:

10 20 30

Initializing from another vector :

#include <bits/stdc++.h>

using namespace std;

int main()

{

    vector<int> vect1{ 10, 20, 30 };

    vector<int> vect2(vect1.begin(), vect.end());

    for (int x : vect2)

        cout << x << " ";

    return 0;

}

Output:

10 20 30