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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T14:05:16+00:00 2026-05-26T14:05:16+00:00

I have a program that load data from a file using std::ifstream and store

  • 0

I have a program that load data from a file using std::ifstream and store the data in a structure. After that, I verify if the data I want was in the file. If it is not, I ask the user to modify the file and press a key. I then reload the file. The problem is that even if the user modified the file, I always get the same data in the file because the file seems to be cache in the application. I’ve seen that in win32 API, it’s possible to use the flag FILE_FLAG_NO_BUFFERING to avoid using a buffered copy when reading a file, but I would like to use that feature with std::ifstream. Is there any way to use the handle created through win32 api with ifstream or anyway to force it directly in std::ifstream ?

Here’s a “simplified” code sample:

SomeStructure  s = LoadData(fileName);
while(!DataValid(s))
    s = LoadData(fileName);


SomeStructure LoadData(const std::string& fileName)
{
    std::ifstream fileStream;
    while(!OpenFileRead(fileName, fileStream))
    {
        std::cout<<"File not found, please update it";
        fileStream.close();
        //Wait for use input
        std::string dummy;
        std::getline(std::cin, dummy);
    }
    //... Read file, fill structure, and return
    std::string line;   
    while(std::getline(fileStream, line) && line!="")
    {
        //At this point, I can see that line is wrong
        StringArray namedatearray=Utils::String::Split(line, "|");
        assert(namedatearray.size()==2);
        //Add data to my structure ( a map)
     }
     fileStream.close();
     //return structure
}

bool OpenFileRead(const std::string& name, std::fstream& file)
{    
    file.open(name.c_str(), std::ios::in);
    return !file.fail();
}

Thanks.

Edit: Of course, it was a mistake because I had two time the same file in two very similar path. Looking at the handle of the file open with process explorer (and not the relative file path made me found it).

  • 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-26T14:05:17+00:00Added an answer on May 26, 2026 at 2:05 pm

    Instead of thinking that this is due to some kind of “buffering”, I would look for the obvious things first.

    • Are you sure the user is changing the same file that you’re reading?
    • Are you certain reloading the data is properly updating your data structure in memory?
    • Are you confident that DataValid() is doing what you want?

    The fact that the OS uses file buffers to increase disk performance is generally not visible from the application level. As long as you’re looking at the same file, the OS knows that the user updated the file, and if you reopen it, then you’ll see the changed data. If the data never even had a chance to get flushed to disk, that won’t affect your application.

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

Sidebar

Related Questions

I'm working on a program, that needs to load data from a text file
I have a CSV file containing data. I want to load it into a
I have a program, that takes a long time to load. Because of this,
I have program that runs fast enough. I want to see the number of
I have a program that creates a Windows user account using the NetUserAdd() API
I have a program that uses the mt19937 random number generator from boost::random. I
I have a program that monitors debug messages and I have tried using a
I have a program that runs osql.exe from microsoft sql server tools directory and
I have a program that's resident in flash and will run from flash. Early
I am working on a program that loads and saves data from text files,

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.