简体   繁体   中英

Why / how are some c++ headers included by default in visual studio?

In visual studio c++, some headers seems to be included by default. For example, I can use std::strncpy or std::string without including <string> or <cstring> , but I cannot use std::cout or std::min() without including <iostream> or <algorithm> .

Then, when I want to compile the source code on unix with g++, I get compilation error if I forgot to add the includes that visual studio did not warm me about because of its implicit includes.

Where does the default includes come from in visual studio? Is there a way to deactivate this behavior for future and existing projects? Note: my visual studio projects are not using precompiled headers.

Visual Studio has no headers included by default. However, some headers include other headers, so if you include <iostream> , that may sometimes include <string> in some compilers, and many headers also include <cstring> . So you are including them yourself, by accident.

Which headers includes which other headers varies from library to library, so always explicitly include the headers used by that file.

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