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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:43:14+00:00 2026-05-26T10:43:14+00:00

I have a Visual Studio 2008 C++ application where I would like to insert

  • 0

I have a Visual Studio 2008 C++ application where I would like to insert a string to an arbitrary point in a file using std::fstream. The file may be as large as 100MB in size, so I don’t want to read it entirely in to memory, modify it, and the re-write a new file.

/// Insert some data in to a file at a given offset
/// @param file stream to insert the data
/// @param data string to insert
/// @param offset location within the file to insert the data
void InsertString( std::fstream& file, const std::string& data, size_t offset );

The method I’m considering now is to read the file in reverse moving each byte from the end out by the length of the data string, then inserting the new string.

What is the most efficient way of accomplishing this?

  • 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-26T10:43:15+00:00Added an answer on May 26, 2026 at 10:43 am

    You’ve just stated one of the basic motivations for database formats, and a need they fulfill.

    Based on that, the solution seems pretty obvious, at least to me: you need to use a database format of some sort, probably along with code that directly supports that format. Nearly any decent db format will support what you’ve said you need, so it’s mostly a matter of deciding which code base provides an interface you like.

    Of course, if you need to produce (for example) a normal text file as the result, then this isn’t really a solution. For a case like this, you pretty much need to bite the bullet and live with copying a lot of data around. At least in my experience, OSes are sufficiently oriented toward reading files sequentially, that unless your modification is quite close to the end of the file, you may easily find it’s more efficient to read and write the whole file rather than copying just enough to make space for the new data.

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

Sidebar

Related Questions

I have a Visual Studio 2008 C++ application where I would like to copy
I have a Visual Studio 2008 C++ application where I would like to convert
I have a Visual Studio 2008 C++ application where I would like to replace
I have a Visual Studio 2008 C++ application that does something like this: template<
I'm using Visual Studio 2008 and have created a setup project for my application.
Using Visual Studio 2008, c#, .net 2.0. I have a Windows Forms client application
I have created a setup project using Visual Studio 2008. After the application is
I have a Visual Studio 2008 C++ Windows Mobile 6 application where I'm using
I have a Visual Studio 2008 C#.NET 3.5 application where I have a string
I have a Visual Studio 2008 C++ application where I'm using a custom allocator

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.