In the source code is it possible to know if a header is included?
This an example of what I need :
#include<iostream>
using namespace std;
int main()
{
char headname[4];
cout<<"Enter a header name : ";
cin>>headname;
#ifdef headname
cout<<headname<<" Defined"<<endl;
#else
cout<<headname<<" Not defined"<<endl;
#endif
return 0;
}
For example, if I enter "iostream", the output should be "iostream Defined".
Yes. Headers usually use include guards such as:
#ifndef MY_HEADER_INCLUDED
#define MY_HEADER_INCLUDED
// [...]
#endif
On my Gentoo Linux / GCC system, looking at the iostream header I see:
#ifndef _GLIBCXX_IOSTREAM
#define _GLIBCXX_IOSTREAM 1
so you could check for _GLIBCXX_IOSTREAM
. If you're not using GCC, open your iostream
header file and see what macros they might have defined.
It should also be pointed out that cout
belongs to the iostream
header, so when _GLIBCXX_IOSTREAM
(in my case) is not defined, the code will also fail to compile. But you can use printf()
for the test.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With