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

推荐订阅源

Help Net Security
Help Net Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
SecWiki News
SecWiki News
Webroot Blog
Webroot Blog
AI
AI
S
Secure Thoughts
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Cloudbric
Cloudbric
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
The Exploit Database - CXSecurity.com
Latest news
Latest news
N
News and Events Feed by Topic
Simon Willison's Weblog
Simon Willison's Weblog
Scott Helme
Scott Helme
S
Schneier on Security
H
Hacker News: Front Page
Forbes - Security
Forbes - Security
T
Troy Hunt's Blog
Know Your Adversary
Know Your Adversary
S
Security Affairs
V
Visual Studio Blog
Stack Overflow Blog
Stack Overflow Blog
博客园_首页
腾讯CDC
GbyAI
GbyAI
有赞技术团队
有赞技术团队
Last Week in AI
Last Week in AI
N
News and Events Feed by Topic
WordPress大学
WordPress大学
The Register - Security
The Register - Security
Engineering at Meta
Engineering at Meta
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Cisco Talos Blog
Cisco Talos Blog
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
Recent Announcements
Recent Announcements
V
V2EX
S
Securelist
Security Archives - TechRepublic
Security Archives - TechRepublic
B
Blog RSS Feed
PCI Perspectives
PCI Perspectives
Security Latest
Security Latest
I
InfoQ
I
Intezer
L
LangChain Blog
雷峰网
雷峰网
NISL@THU
NISL@THU
博客园 - 【当耐特】
Microsoft Azure Blog
Microsoft Azure Blog
阮一峰的网络日志
阮一峰的网络日志

博客园 - 今夜太冷

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