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 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

Ask A Question

Stats

  • Questions 230k
  • Answers 230k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer After a configurable number of failed logins (maxInvalidPasswordAttempts, default =… May 13, 2026 at 2:04 am
  • Editorial Team
    Editorial Team added an answer For 1 and 2: records are value types, while classes… May 13, 2026 at 2:04 am
  • Editorial Team
    Editorial Team added an answer Doing the following appears to resolve the issue, but I… May 13, 2026 at 2:04 am

Related Questions

I have a Visual Studio 2005 C++ project, it is a console application. I
I've looked at this explanation on Wikipedia , specifically the C++ sample, and fail
In short: I want to monitor selected calls from an application to a DLL.
I have a C++ class that I'm using from my Objective-C++ controller in my

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.