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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:03:21+00:00 2026-05-23T08:03:21+00:00

Application uses RapidXML to edit XML file. Editing is not automated and takes place

  • 0

Application uses RapidXML to edit XML file. Editing is not automated and takes place occasionally: XML content is displayed in GUI and user performs some actions which change XML. Each change must be saved to disk immediately.

Loading RapidXML document object requires copying the content of the file into a string. Each change in a document is followed by copying the content of the document object back into the file.

File is used both for input and output in this example. Shall a single std::fstream object be used for all input/output operations in this case? It would be opened once, at the application startup, used for input/output, and closed at the end of the application.

Or, shall local (temporary) instances of std::ifstream and std::ofstream be used whenever file input/output needs to be performed? E.g. std::ifstream to be used at the beginning for reading the file (open, read, close); similarly, std::ofstream instance to be used whenever DOM must be exported into the file (open, write, close).

I am not concerned about performances here (due to the nature of the application) but am curious about the proper choice of file stream objects in this case.

  • 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-05-23T08:03:22+00:00Added an answer on May 23, 2026 at 8:03 am

    Editing files in place when the amount of data to re-write is different from the original data is a real pain. If your file format requires data to be sequential and has no syntax for holes, then you don’t really have a choice but to re-write the file (at least from the start of the modified position).

    Also, there are additional constraints. If you require the data to be flushed to disk before continuing, then you might be able to use a single std::fstream for multiple edits. Operating systems typically don’t flush the file to disk even when you invoke the flush() method on file streams. Some platforms offer non-portable solutions to really force a write. So if you need it to be flushed to disk, your best bet is to actually close the file.

    Thus, especially for critical applications, I would recommend the 2nd approach (ifstream at initial load, ofstream at each write). I would also recommend writing to a temporary file, then moving the complete re-write to the preferred location, replacing the original files. This ensures you won’t have any data loss (at least on systems that offer atomic file move).

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

Sidebar

Related Questions

Our application uses a XML configuation file. I thought that it would be nice
Our application uses Hibernate with Sql Server 2005. Being a DBA, I am not
My application uses several threads with well-defined names (i.e. not a thread pool with
My application uses Lucene.NET to index various text files. Since each text file is
My application uses JDBC database drivers. I load these from a jar file, db2jcc.jar
Currently our Java application uses the values held within a tab delimited *.cfg file.
My application uses Spring XML configuration. I must add Spring Social's functionality(i want to
Our application uses an SQLite database file to hold some data in it. The
My application uses a settings file settings.txt to save the currently set values of
My application uses the 'twisted.web.client.Agent' to get web content. But the Agent class requires

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.