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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With