Hey all,

need some help on little issue im having. I have 2 programs and I am writing an interface to link the 2 of them in MC VC 6 MFC. There is an input text file to input data for the second program. My dialog interface saves the input text file and then executes the program. Here is where my probelm lies, the program uses the previously saved data. I can open the text file and see that the correct data is in there and if i run the program manually it works perfectly but when I write the text file, close the text file and execute the program all in the one code the code uses previously saved input data. Has anyone any ideas on how I can get around this or on what exactly is going on. Thanks in advance.

Colm

It may be a glitch in the way you read files. First make sure in your code every time you open a file you close it. Then restart your system and try to run the program again. If it did not close the file, things like this can happen. Next, make sure your reading the file again not reading the old data. And could you tell me what file reader/writer your using? I like fstream but you may be using File.

Hey u8sand,

thanks for the reply. I am using fstream. I am closing any file that i open in the code and I have tried rebooting but no luck. ave you any other ideas, thanks again.

Colm

>First make sure in your code every time you open a file you close it.

Any fstream (and thus also ifstream / ofstream) object has what's called a destructor, this destructor will close the file automatically when the file-object goes out-of-scope.
So actually there's no need to explicitly close a file as it will be closed automatically (as the object's destructor will be called then; this is only the case when the object goes out-of-scope).
But when your program just needs to read/write some data from/to a file, and then still has to execute loads of instructions (within the same scope as the file-object), then I would advise you to close the file manually using the close() method.

The only other thing i can think of is that the file's text IS being updated, but you didn't retreive the updated text into the program. So maybe make a timer or make a button that will update the information from the text file.

BTW sorry about the late post, i went out :/

This article has been dead for over six months. Start a new discussion instead.