vector was not declared in this scope【记一次粗心大意犯的错误】

vector was not declared in this scope

【记一次粗心大意犯的错误】

#include <iostream>
#include <vector>

int main(int argc,char** argv)
{
	vector<int> vec;
	return 0;
}

  因为要使用vector容器,这里包含了vector的头文件。当程序编译时,竟然报了错!竟然报了错!(黑人问号脸???)

[Error] ‘vector’ was not declared in this scope

  一脸懵,明明包含了vector的头文件为什么会报错,说vector未定义?
  检查错误,一度怀疑IDE未打开-std=c++11标准。
  看了一圈发现,自己没有添加std::作用域!!!

以前写代码,直接using namespace std;,没有在意容器这里的问题,仅以此贴为记!

  正确的代码:

#incldue <iostream>
#include <vector>

int main(int argc,char** argv)
{
	std::vector<int> vec;
	return 0;
}
发布了30 篇原创文章 · 获赞 58 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/annjeff/article/details/99658697