Author Topic: Does codeblocks automatically #include names from C++ standard library?  (Read 4591 times)

neilcpp

  • Guest
Strange, but i have noticed that for some standard library routines - I dont have to state the #include directive in the source file - and it seems the names are automatically found.

for example, I can use std::exception() and std::cerr - without having to use #include <exception>.
I have noticed other automatic includes as well e.g std::string - without #include <string>

Can anyone shed any light on this?

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5491
Re: Does codeblocks automatically #include names from C++ standard library?
« Reply #1 on: February 21, 2009, 05:02:59 pm »
has nothing to do with CB, but with the way the header files of your files are constructed.
You were just lucky it works now, in an update it can change again. Apparently one header includes another etc .. and by that you got the thing you needed.

Just make sure you include what you need with the correct headers, see the standard.

Offline ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5916
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: Does codeblocks automatically #include names from C++ standard library?
« Reply #2 on: February 21, 2009, 05:31:25 pm »
@neilcpp
I just tested for you.

If you don't add any include file in your cpp file, then, the standard c++ files can't be parsed.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.