Skip to main content
GameDev.net gamedev.net
🔒 Locked

Opening 2 Files

Started by Programmer One Dec 20, 2001 at 7:53 PM 0 replies 450+ views
Original Post
Programmer One
Programmer One
Say if you have 2 programs that have the same procedure:
  
class FileManip {
public:
   FileManip(); //constructor

   ~FileManip(); //Destructor

   void WriteFile( Char * ); //Writes data to a file

   void ReadFile(); // Reads data from a file

private:
   Char FilePath[225];
   Char DataBuffer[100];
};

FileManip::FileManip();
{
   FilePath[] = "c:\Default.dat";
   DataBuffer[] = "Empty";
}

~FileManip::FileManip()
{
}

void FileManip::WriteFile( Char Data[] )
{
   ofstream FP(FilePath);
   FP << Data;
   FP.Close();
}

void FileManip::ReadFile()
{
   char Data[];   
   ifstream FP(FilePath);
   FP >> Data;
   FP.CLose();
}
  
And they both use it at the same time...would the program get a "File Access Denied" error? Since both programs are using the files at the same time... If it would get an error, how can I get around it? ...advice from the insane
hollowMedia
hollowMedia

As written in msdn ---

fstream( const char* szName, int nMode, int nProt = filebuf::openprot ); 




...


nProt

The file protection specification; defaults to the static integer filebuf::openprot, which is equivalent to the operating system default, filebuf::sh_compat, under MS-DOS. The possible nProt values are as follows:

filebuf::sh_compat Compatibility share mode (MS-DOS only).


filebuf::sh_none Exclusive mode — no sharing.


filebuf::sh_read Read sharing allowed.


filebuf::sh_write Write sharing allowed.
The filebuf::sh_read and filebuf::sh_write modes can be combined with the logical OR ( || ) operator.


Hope that answers your question.
[xian]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.