Why does omission of “#include ” only sometimes cause compilation failures?

后端 未结 7 2230
清歌不尽
清歌不尽 2020-11-22 14:23

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

相关标签:
7条回答
  • 2020-11-22 15:19

    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>.)

    0 讨论(0)
提交回复
热议问题