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;
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章