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?

Recommended Answers

All 7 Replies

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.

Ohh, I see.

Thanks so much for that info!!

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

I am using xCode Version 6.4 (6E35b) compiler.

Hope this helps.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.