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 7930431
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T20:25:22+00:00 2026-06-03T20:25:22+00:00

I’m a C++ beginner and having just finished C++ Primer, I’m playing around with

  • 0

I’m a C++ beginner and having just finished C++ Primer, I’m playing around with a few projects of my own. One thing I’m noticing as I do this is that while C++ Primer tended to emphasize std::fstream as the way to go for file IO, many programs instead use FILE*.

Is there any reason for this? If there is, in what situations would/should you use fstream over FILE or is there a 3rd option unknown to me that you would recommend?

Thanks!

  • 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-03T20:25:24+00:00Added an answer on June 3, 2026 at 8:25 pm

    The only reason to use stdio (i.e. the FILE* family of functions) in C++ is to interface with C code taking FILE* parameters. Many people who learned C and/or C++ using stdio believe these functions are somehow superior. The main complaint is that format specifiers using stdio are so much shorter. Unfortunately, they are also error-prone and despite warnings pointing out inconsistencies between format specifiers and actual arguments I have yet to see a program which uses stdio non-trivial and correctly.

    The one omission in IOstreams which stdio does better is that the scanf() functions can do some interesting parsing. This can be added to IOstreams quite easily but it isn’t part of the standard library (and it isn’t as terse as the format specifiers).

    Personally, I consider the drawbacks irrelevant compared to the advantages:

    • type-safe reading and writing
    • user-defined support for user-defined types
    • support for user-defined sources and destinations
    • to a lesser degree control over formatting of numerical types

    Due to a series of articles and some extremely bad implementations of early IOstreams (some of which still seem to linger in popular platforms) the C++ streams have gained an incorrect reputation of being slow. Yes, it is possibe to make sure that they are a lot slower than stdio but is definitely possible to implement them with similar performance as stdio. There are a few easy performance mistakes the user needs to avoid, however:

    1. Do not use std::endl. Period. If you really mean to write a newline followed by a flush say so: out << '\n' << std::flush. This is what std::endl does but std::endl is incorrectly used in the vaste majority of the cases with the unintended flush causing major performance problems.
    2. Make sure the library doesn’t waste time keeping things in sync with stdio operations: call std::sync_with_stdio(false); unless you are mixing output to the standard stream object (std::cin, etc. and stdin, etc.). Although the effect is only required for the standard stream objects, there are bad implementations of IOstreams where this also affects file streams.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I am reading a book about Javascript and jQuery and using one of the
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString

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.