Is it possible to open file twice?
-
Hi All, Is it possible to open the file twice? I am using CStdioFile, i created two objects of type CStdioFile and assigning the same file for both the objects. one file opened for writing(modeReadWrite) the data and the other file opened for reading(modeRead) the data. In this case my application is crashing. please give me some solution. CStdioFile obj1; CStdioFile obj2; obj1.Open("file1.txt", CStdioFile::modeReadWrite); ..... ..... ..... obj2.open("file1.txt", CStdioFile::modeRead); ..... ..... obj2.close(); .... ... obj1.close(); Thanks in advance! Regards, Anil
-
Hi All, Is it possible to open the file twice? I am using CStdioFile, i created two objects of type CStdioFile and assigning the same file for both the objects. one file opened for writing(modeReadWrite) the data and the other file opened for reading(modeRead) the data. In this case my application is crashing. please give me some solution. CStdioFile obj1; CStdioFile obj2; obj1.Open("file1.txt", CStdioFile::modeReadWrite); ..... ..... ..... obj2.open("file1.txt", CStdioFile::modeRead); ..... ..... obj2.close(); .... ... obj1.close(); Thanks in advance! Regards, Anil
Why do you want to do such a thing ? Why don't you simply open and read the full file in memory, make the changes in memory and then write back everything to the file afterwards ?
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++ -
Why do you want to do such a thing ? Why don't you simply open and read the full file in memory, make the changes in memory and then write back everything to the file afterwards ?
Cédric Moonen Software developer
Charting control [v3.0] OpenGL game tutorial in C++yes, thankyou!
-
Hi All, Is it possible to open the file twice? I am using CStdioFile, i created two objects of type CStdioFile and assigning the same file for both the objects. one file opened for writing(modeReadWrite) the data and the other file opened for reading(modeRead) the data. In this case my application is crashing. please give me some solution. CStdioFile obj1; CStdioFile obj2; obj1.Open("file1.txt", CStdioFile::modeReadWrite); ..... ..... ..... obj2.open("file1.txt", CStdioFile::modeRead); ..... ..... obj2.close(); .... ... obj1.close(); Thanks in advance! Regards, Anil
Member 4399771 wrote:
In this case my application is crashing.
At what point?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Man who follows car will be exhausted." - Confucius
-
Hi All, Is it possible to open the file twice? I am using CStdioFile, i created two objects of type CStdioFile and assigning the same file for both the objects. one file opened for writing(modeReadWrite) the data and the other file opened for reading(modeRead) the data. In this case my application is crashing. please give me some solution. CStdioFile obj1; CStdioFile obj2; obj1.Open("file1.txt", CStdioFile::modeReadWrite); ..... ..... ..... obj2.open("file1.txt", CStdioFile::modeRead); ..... ..... obj2.close(); .... ... obj1.close(); Thanks in advance! Regards, Anil
-
Yes you can, simply use 2 handles (or objects or whatever your language wants you to use). Be aware of the folloing: - The OS sees this as file sharing, so open in shared mode. - You will have 2 independent filepointers. Rozis
To Cedric and David: There are many cases opening a file twice can be handy. The simplest example is a Word document on a network. The first user reads it shared, read-write, the next shared, readonly. Be aware many DBMS use this for concurrent access (with some intelligence around). Rozis