#include <cctype>

In a book for C++ for class, it says for functions like isupper, islower,isprint etc. the header file <cctype> is needed. I tested out on visual studio without the header file but it still took the program and compiled. Why is that?

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;
int main()
{
	char letter = 'a';
	if (isupper(letter))
		cout << "Letter is uppercase.\n";
	else
		cout << "Letter is lowercase.\n";

	cin.get();
	return 0;
}
Depending on the standard library implementation, some headers may include other headers indirectly. However, you should not rely on this, because which MSVC's <iostream> may indirectly include <cctype>, the same may not be true on GCC or Clang. You should always include the headers you use.
Visual studio's "pch.h" (the header they use now which replaced "stdafx.h") will have certain headers included as helios mentioned. This means code working on Visual Studio will break if copied and pasted else where if you leave out the actual header that the functions used exist in.
Visual studio's "pch.h" (the header they use now which replaced "stdafx.h") will have certain headers included

This is why I create an "empty project" every time I start a new project.

So I don't include unnecessary headers and don't activate "Precompiled Headers (pch)."
Topic archived. No new replies allowed.