7stud: MS-Windows function _fsopen() allows and enforces opening a file in exclusive mode (see example below). I'm not running MS-DOS, but XP (which has NO MS-DOS code in it)
So why doesn't fstream??? (answer: c++ fstream is a crappy horrible class.)
Code:
#include <stdio.h>
#include <share.h>
int main() /* program main begins execution */
{
FILE* fp = _fsopen("myfile.txt","a",_SH_DENYRW);
if(fp != NULL)
{
fprintf(fp,"Hello World\n");
printf("File opened ok -- press <Enter>");
getchar();
fclose(fp);
}
else
{
printf("File open failed --press <Enter>");
}
return 0; /* indicates successful program execution */
}