Hi all!

Whenever I am working with my code in my main.cpp file, I can call character-handling functions like

  • isdigit
  • isalpha
  • isspace
  • toupper

without importing the cctype library. However, my C++ How to Program Book shows that the cctype library must be imported before the functions can be used.

Why and how am I able to access these (working) functions without importing the cctype library in my main.cpp file?

1 Year
Discussion Span
Last Post by nathan.pavlovsky

What other headers are you using? One of them must be including cctype for its own purposes.


More than likely one of the headers that you are including in your code is including that header. This is something you should NOT rely on. You should explicitly include all headers needed to compile your code and not rely on something else including it for you. A different compiler might not include that header for you and then your code will fail to compile making it non portable.


nathan.pavlovsky: I know that you have the explanation, but the question itself may indicate a possible problem. I say this because it used to be common for compiler packages to cross-include headers in order to support older code, but most newer compilers' libraries have eliminated most or even all of these cross-inclusions. Running into a cross-inclusion issue is uncommon (but not unheard of) in recent releases of most C/C++ compilers. Which compiler (and IDE, if any) are you using, and what is/are the version number(s)?


Hmmn, that is the most recent version, so you should be fine. My concern was mostly that you might have had an older compiler, and might have wanted to upgrade if it were.


Oh... OK. Thanks for asking about this, though. I appreciate any perspective that you may have to offer.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.