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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:40:47+00:00 2026-05-11T09:40:47+00:00

C++ file I/O is tougher than C file I/O. So in C++, creating a

  • 0

C++ file I/O is tougher than C file I/O. So in C++, creating a new library for file I/O is useful or not? I mean <fstream> Can anyone please tell are there any benefits in C++ file I/O ?

  • 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-11T09:40:48+00:00Added an answer on May 11, 2026 at 9:40 am

    Opinion

    I don’t know of any real project that uses C++ streams. They are too slow and difficult to use. There are several newer libraries like FastFormat and the Boost version that claim to be better there was a piece in the last ACCU Overload magazine about them. Personally I have used the c FILE library for the last 15 years or so in C++ and I can see no reason yet to change.

    Speed

    Here is small test program (I knock together quickly) to show the basic speed problem:

    #include <stdio.h> #include <time.h>  #include<iostream> #include<fstream>  using namespace std;  int main( int argc, const char* argv[] )     {     const int max = 1000000;     const char* teststr = "example";      int start = time(0);     FILE* file = fopen( "example1", "w" );     for( int i = 0; i < max; i++ )         {         fprintf( file, "%s:%d\n", teststr, i );         }     fclose( file );     int end = time(0);      printf( "C FILE: %ds\n", end-start );      start = time(0);     ofstream outdata;     outdata.open("example2.dat");     for( int i = 0; i < max; i++ )         {         outdata << teststr << ":" << i << endl;         }     outdata.close();     end = time(0);      printf( "C++ Streams: %ds\n", end-start );      return 0;     } 

    And the results on my PC:

    C FILE: 5s C++ Streams: 260s  Process returned 0 (0x0)   execution time : 265.282 s Press any key to continue. 

    As we can see just this simple example is 52x slower. I hope that there are ways to make it faster!

    NOTE: changing endl to ‘\n’ in my example improved C++ streams making it only 3x slower than the FILE* streams (thanks jalf) there may be ways to make it faster.

    Difficulty to use

    I can’t argue that printf() is not terse but it is more flexible (IMO) and simpler to understand, once you get past the initial WTF for the macro codes.

    double pi = 3.14285714;      cout << "pi = " << setprecision(5)  << pi << '\n'; printf( "%.5f\n", pi );      cout << "pi = " << fixed << showpos << setprecision(3) << pi << '\n';  printf( "%+.3f\n", pi );      cout << "pi = " << scientific << noshowpos << pi<< '\n'; printf( "%e\n", pi ); 

    The Question

    Yes, may be there is need of a better C++ library, may be FastFormat is that library, only time will tell.

    dave

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

Sidebar

Related Questions

FILE : hello world foo bar How can I remove all the empty new
File folder2 = new File(C:\\Users\\user\\fypworkspace\\TextRenderer); File[] listOfFiles2 = folder.listFiles(); System.out.println(Please enter the required word
FILE *out=fopen64(text.txt,w+); unsigned int write; char *outbuf=new char[write]; //fill outbuf printf(%i\n,ftello64(out)); fwrite(outbuf,sizeof(char),write,out); printf(%i\n,write); printf(%i\n,ftello64(out));
file.each_line do |line| #skip the first one/not a user 3.times { next } if
File -> New Project for ASP.NET MVC projects used to generate controllers with virtual
File lstFile = new File(lstFileName).withWriter{out-> archivedFiles.each {out.println it.name} } archivedFiles is a List objects
FILE *new = fopen(new.out, w+); // creates a new file that didnt exist before
File.isFile() and File.isDirectory() both return false not only when the File is not the
// File (or directory) to be moved File file = new File(filename); // Destination
File C:\Users\Randy\Documents\XML\mealstxt.xml is not valid. Content model of element 'recipes' disallows element 'heading' at

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.