include and using namespace in C++

前端 未结 4 1764
日久生厌
日久生厌 2021-02-06 02:57

for using cout, I need to specify both:

#include

and

using namespace std;

4条回答
  •  名媛妹妹
    2021-02-06 03:59

    The #include references the header file that defines cout. If you're going to use cout, then you will always need the include.

    You do not need to using namespace std;. That's simply allows you to use the shorthand cout and endl and the like, rather than std::cout and std::endl where the namespace is explicit. Personally I prefer not to use using namespace ... since it requires me to be explicit in my meaning, though it is admittedly more verbose.

提交回复
热议问题