簡體   English   中英

如何在C ++中聲明向量?

[英]How to declare vectors in C++?

我正在嘗試在代碼中使用字符串向量而不是字符串數組,但是顯然我在向量的聲明中缺少了一些細節。 使用以下代碼,我收到此錯誤: 'vector' was not declared in this scope

// Try to implement a vector of string elements

#include<iostream>

using namespace std;

int main() {
    const int MAX_ITEMS = 10;
    vector<string> my_vector(MAX_ITEMS);
    return 0;
}

如何正確聲明向量?

您必須包括標題:

#include <vector>
#include <string>

您應該添加以下內容:

#include <vector>
#include <string>

你需要:

#include <vector>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM