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

  • Home
  • SEARCH
  • 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 47369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T16:06:43+00:00 2026-05-10T16:06:43+00:00

In new C++ code, I tend to use the C++ iostream library instead of

  • 0

In new C++ code, I tend to use the C++ iostream library instead of the C stdio library.

I’ve noticed some programmers seem to stick to stdio, insisting that it’s more portable.

Is this really the case? What is better to use?

  • 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. 2026-05-10T16:06:44+00:00Added an answer on May 10, 2026 at 4:06 pm

    To answer the original question:
    Anything that can be done using stdio can be done using the iostream library.

    Disadvantages of iostreams: verbose Advantages    of iostreams: easy to extend for new non POD types. 

    The step forward the C++ made over C was type safety.

    • iostreams was designed to be explicitly type safe. Thus assignment to an object explicitly checked the type (at compiler time) of the object being assigned too (generating an compile time error if required). Thus prevent run-time memory over-runs or writing a float value to a char object etc.

    • scanf()/printf() and family on the other hand rely on the programmer getting the format string correct and there was no type checking (I believe gcc has an extension that helps). As a result it was the source of many bugs (as programmers are less perfect in their analysis than compilers [not going to say compilers are perfect just better than humans]).

    Just to clarify comments from Colin Jensen.

    • The iostream libraries have been stable since the release of the last standard (I forget the actual year but about 10 years ago).

    To clarify comments by Mikael Jansson.

    • The other languages that he mentions that use the format style have explicit safeguards to prevent the dangerous side effects of the C stdio library that can (in C but not the mentioned languages) cause a run-time crash.

    N.B. I agree that the iostream library is a bit on the verbose side. But I am willing to put up with the verboseness to ensure runtime safety. But we can mitigate the verbosity by using Boost Format Library.

    #include <iostream> #include <iomanip> #include <boost/format.hpp>  struct X {  // this structure reverse engineered from    // example provided by 'Mikael Jansson' in order to make this a running example      char*       name;     double      mean;     int         sample_count; }; int main() {     X   stats[] = {{'Plop',5.6,2}};      // nonsense output, just to exemplify      // stdio version     fprintf(stderr, 'at %p/%s: mean value %.3f of %4d samples\n',             stats, stats->name, stats->mean, stats->sample_count);      // iostream     std::cerr << 'at ' << (void*)stats << '/' << stats->name               << ': mean value ' << std::fixed << std::setprecision(3) << stats->mean               << ' of ' << std::setw(4) << std::setfill(' ') << stats->sample_count               << ' samples\n';      // iostream with boost::format     std::cerr << boost::format('at %p/%s: mean value %.3f of %4d samples\n')                 % stats % stats->name % stats->mean % stats->sample_count; } 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing some new code that will throw a custom exception - I
Typically when writing new code you discover that you are missing a #include because
I need to optimize code to get room for some new code. I do
Is it possible to actually make use of placement new in portable code when
I have have some code which adds new cells to a table and fills
At my workplace, we tend to use iostream , string , vector , map
(x-posted to guice mailing list) I'm trialling Guice on a new library that will
I am trying to integrate some new code I wrote for programmatically interacting with
I was talking to a friend of mine that through my new code I
I'm working on some C++ code that uses libsigc++ for signaling (eventing.) I'm quite

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.