error: ‘cout’ was not declared in this scope

error: ‘cout’ was not declared in this scope

C++ 编程时,使用 coutendl时可能会遇到error: ‘cout’ was not declared in this scope这样的错误提示。

这是因为 c++ 在使用时,每一块内容涉及到一个命名空间(函数域)

可以通过以下两种方式处理

1、

std::cout << "a" << std::endl;

std::代表的是 cout 定义在std空间当中,::为域操作符,
std::cout的意思为从std空间当中,找到cout的定义。

2、在代码中声明使用这个命名空间,这样在编码中就不用再加std::

using namespace std;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章