Why do you use conio.h?

1 answer

Answer

1089319

2026-07-11 05:10

+ Follow

You include stdio.h when writing C code. If you are writing C++ code then you must include cstdio instead. Both headers implement the C standard input and output library but cstdio is compliant with C++.

Consider the following :

#include

int main()

{

printf("Hello world\n");

std::printf("Hello world\n"); // ERROR!

}

The error occurs because there's no guarantee the printf symbol resides in the std namespace. There's a small possibility it does reside there, but it is only guranteeed to exist in the global namespace. Thus the risk of error is high.

Now consider the following:

#include // also includes stdio.h

int main()

{

using std::printf;

printf("Hello world\n");

std::printf("Hello world\n");

}

The cstdio header guarantees all symbols defined in stdio.h now appear in the std namespace (where all standard library symbols rightly belong). Although there's no guarantee those same symbols also reside in the global namespace, the using keyWord can be used to inject those symbols into the global namespace. In this case the using keyWord is unnecessary; the code will compile with or without it.

It's important to recognise the difference between C++ standard library headers (those with no extension) and the equivalent C headers (those with a .h extension). C headers guarantee all symbols are imported to the global namespace and possiblythe std namespace. C++ headers guarantee all symbols are imported to the std namespace and possibly the global namespace. In most cases, the C++ header simply modifies the equivalent C header to render it compliant with C++. This isn't always the case, but ultimately it is much easier to inject symbols to the global namespace (with using) than it is to inject to the std namespace. The C++ headers take care of all the messy stuff for you and are less problematic in the long run.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.