I am a beginner with C++. When I write the code sometimes I write #include
and the code works, other times I don\'t write #include
It is possible that other headers that you do include have #include <string>
in them.
Nonetheless, it is usually a good idea to #include <string>
directly in your code even if not strictly necessary for a successful build, in case these "other" headers change - for example because of a different (or different version of) compiler / standard library implementation, platform or even just a build configuration.
(Of course, this discussion applies to any header, not just <string>
.)