2

I use Dev C++ 5.11. TDM-GCC 4.8.1

And this code runs well.

#include<iostream>
using namespace std;

int main()
{
printf("%d\n", 42);
cout << "good";
}

But as far as I know, iostream does not include "printf". (http://en.cppreference.com/w/cpp/header/iostream)

Why this code run? iostream acutally include printf? Is it a kind of standard?

3

1 Answer 1

5

The list of header files included in a system/standard header file is library implementation dependent (that is usually associated with the compiler you're using), and (as far as I remember) the C++ standard does not prohibit one header file from automatically including another one

In your case <iostream> is probably also #including <stdio.h> (or <cstdio>).

Relying on a header file being included in another is non portable to different standard libraries, compilers and platforms, so it's better to make sure that you explicitly #include everything you need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.