gpt4 book ai didi

c++ - 如何在 C++ 中声明 vector ?

转载 作者:塔克拉玛干 更新时间:2023-11-03 08:05:23 24 4
gpt4 key购买 nike

我试图在我的代码中使用一个字符串 vector 而不是一个字符串数组,但显然我在 vector 声明中遗漏了一些细节。使用以下代码,我收到此错误:‘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;
}

我应该如何正确声明 vector ?

最佳答案

你应该添加这些包括:

#include <vector>
#include <string>

关于c++ - 如何在 C++ 中声明 vector ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2303435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com