简体   繁体   中英

For using a standard library function in C++, what exactly is the relationship between its header file and std namespace?

In C++, since the namespace std contains the declaration of all standard library functions, then why do we need to include iostream header to use I/O functions. Can we not just write 'using namespace std' so that the compiler knows where to get the definition? I want to know the need for including a header file for using any feature like strings too if that function declaration is already present in std namespace.

The compiler finds the declared namespace std in the included headers. It cannot know where to get the definition from unless you don't specify it by including libraries.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM