Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8988077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:56:26+00:00 2026-06-15T21:56:26+00:00

What should I include in C++ programs, stdio.h or cstdio ? and Why? Why

  • 0
  • What should I include in C++ programs, stdio.h or cstdio? and Why?
  • Why two header files which provide the same functionality?
  • What does the standard say regarding this?
  • How should I go about including other such headers, Is there a base rule that I should follow?
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T21:56:27+00:00Added an answer on June 15, 2026 at 9:56 pm

    Consider the following programs:

    Sample 1:

    #include<stdio.h>
    
    int main()
    {
        printf("Hello World");
        return 0;
    }
    

    Sample 2:

    #include<cstdio>
    
    int main()
    {
        printf("Hello World");
        return 0;
    }
    

    Both work as expected. So which usage is more appropriate?
    The answer is: Neither! Surprised? Read on.

    The C++ Standard library provides all standard C headers for compatibility reason, while C++ as a language also provides all the equivalent headers. As a convention,

    • No C++ standard library headers(apart from ones include for C compatibility) have any file extensions, and
    • All C++ equivalent of C headers begin with cxxxxx.

    The C++ Standard mentions this under Annex D (normative) Compatibility features:

    Standard Citation

    §2 mentions the important distinguishing point. This rule applied to the examples above means:

    • Including cstdio imports the symbol names in the std namespace and possibly in the Global namespace.
    • Including stdio.h imports the symbol names in the Global namespace and possibly in the std namespace.

    Let us apply this rule to our sample codes and measure the pros and cons:

    Sample 1:
    This brings all the symbols from stdio.h in the global namespace. Advantage is that you can use the symbols without any qualification since they are imported in the global namespace. Downside is that you end up polluting the global namespace with many symbol names that you will probably never use. This might lead to symbol name collision. In C++ always consider the global namespace as a minefield and avoid it as much as possible.

    Sample 2:
    This is a very bad practice because there is no guarantee that the implementation will put the symbols in global namespace, the standard simply does not demand to do so. We are simply relying on the behavior of one particular compiler implementation. We cannot and should not assume that all compilers will do so. So strictly speaking the program is not standard approved and this usage is not portable across all implementations.

    So what is the correct usage?

    The correct usage is to use cstdio and fully qualify the symbol names or else bring them in scope with using declarations. This guarantees all symbols we use are present in std namespace and we are not polluting the global namespace. Example of correct usage:

    Sample 3:

    #include<cstdio>
    
    using std::printf;
    
    int main()
    {
        printf("Hello World");
        return 0;
    }
    

    Note that the directive using namespace std;, especially in a header, is not a good option and you should always use using declarations.

    Note that we consider stdio.h vs. cstdio here just a sample use case, in practice it applies to all most cxxxx and xxxx.h headers, except a few like <math.h> and <cmath>.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This program should calculate the value of 2^1+2^2 + ... + 2^10: #include <stdio.h>
Should I #include everything I need in every header/cpp file? I am working on
#include <stdio.h> int main() { unsigned char i=0x80; printf(%d,i<<1); return 0; } Why does
What should be the output of this C program? #include<stdio.h> int main(){ int x,y,z;
Say I have this C program. #include <stdio.h> int main(void) { int monday =
I was just wondering what license agreement I should include in an XNA Framework
From what I understand, the output from the following script should include Win32_PerfRawData_PerfDisk_PhysicalDisk in
I'm trying to implement PayPal Adaptive Payments API. Into the headers I should include
How to develope an efficent job scheduling with constraints?? The scheduler should include these
I need to collect usage information on my on-demand application. This should include things

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.