answersLogoWhite

0

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.

User Avatar

Wiki User

11y ago

What else can I help you with?

Related Questions

How do you use conioh header in c plus plus?

just as you do it in C.


What is the full form of conioh?

Console Input Output Header


What is the difference between stdioh and conioh?

Their name, content and function.


What is the function of conioh in C?

Not in C, only in TurboC.Direct console input-output (MS-DOS specific).


Functions of conioh and processh header files?

Loads of them. Consult your help, or load these headers into a text-editor.


Why cannot you include conioh in your c program when you program in Linux system?

You could, if you had conio.h in linux, but you don't have, that's why.


What does conioh in programming mean?

conio.h is a library function which is predefined in the header file and 'clrscr();','getch();' and many other functions come under this.


Which library file contain the definition of stdioh and conioh header file function definition in C language?

Platform dependent, possibly LIBC.LIB or something like that.


When to use me and you or you and i?

If you would use 'I' in the singular, then use 'you and I'. If you would use 'me', then use 'you and me'.


What do you use to work out equations on excel?

You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.You use the formulas and functions.


Where is All of the imvu use codes?

they are mostly actions it has some moods CODES: *use 90-pacman *use 200-tresure chest *use 2001-banna *use 2044-cry *use 2050-oooh *use 2053-Puke *use 2061-Huh *use 2063-wassamatta *use 2064-yay *use 2066-Loser *use 2067-shocked *use2068-rocker *use 2072-Flip *use 2073-air guitar *use 2074-talk to the hand *use 2076-Burp *use 2078-Crazy *use 2082-bigyawn *use 2086-strong *use 2088-score *use 2090-wink *use 2091-HeadShake *use 2093-thums up *use 2097-Hmm *use 2098-candlestick *use 2103-old mood *use 2104-flirty mood *use 2105-bashful mood *use 2106-groovin mood *use 2107-peace *use 2108-fartarm *use 2109-terrifide mood *use 2110-tantrum


What is the continuum of chemical use?

The continuum of chemical use refers to a spectrum ranging from no use to harmful or addictive use. It includes experimental use, recreational use, regular use, problematic use, and dependent use. Understanding this continuum can help in assessing, preventing, and treating substance use disorders.