Reputation: 265
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.
Upvotes: 6
Views: 1114
Reputation: 66922
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.
Upvotes: 8