What requires me to declare “using namespace std;”?

后端 未结 12 2179
抹茶落季
抹茶落季 2020-12-17 10:55

This question may be a duplicate, but I can\'t find a good answer. Short and simple, what requires me to declare

using namespace std;

in C+

12条回答
  •  暖寄归人
    2020-12-17 11:23

    It's used whenever you're using something that is declared within a namespace. The C++ standard library is declared within the namespace std. Therefore you have to do

    using namespace std;
    

    unless you want to specify the namespace when calling functions within another namespace, like so:

    std::cout << "cout is declared within the namespace std";
    

    You can read more about it at http://www.cplusplus.com/doc/tutorial/namespaces/.

提交回复
热议问题