c++ - 为什么 dev C 不运行这个脚本?出于某种原因,它不喜欢我的 vector 声明

标签 c++

我正忙于阅读我的 C++ 书籍,似乎无法在没有错误“[Error] 'vector' 未在此范围内声明”的情况下运行它

#include <iostream>
using namespace std;

int main(){
string word;
string previous;
string current;

vector<string> dislikes(4);
dislikes [0] = "bob";
dislikes [1] = "cat";
dislikes [2] = "pineapple";
dislikes [3] = "stackoverflow";

while(cin >> current){
for(i = 0; i<dislikes.size(); ++i){
    if(current==dislike[i]){
        cout << "BLEEP ";}

    else{cout << current << " "}

}   
    previous = current;
}

}
return 0;
}

最佳答案

您需要包含 vector 类型的头文件:

#include <vector>

在 C++ 中,所有内容都必须在代码中使用之前声明,标准库的声明在 standard library header files 中。 .

关于c++ - 为什么 dev C 不运行这个脚本?出于某种原因,它不喜欢我的 vector 声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18286852/

相关文章:

c++ - 为什么我收到此代码的错误?

c++ - 如何以最小延迟依次调用两个函数?

c++ - 函数调用可以重新排序吗

c++ - 在 C++ 中分配内存时发出 SIGKILL

C++从动态分配转换为引用

c++ - 使用 C++ 从 bios 获取 Assets 标签和序列号

C++ : Check if the template type is one of the variadic template types

c++ - 什么是 "metadata operation failed"VS2008 链接器错误?

c++ - 从 #define 宏填充哈希表

c++ - 如何修复对 strstr 没有匹配的函数调用