是否可以同时用两个程序写入和读取文本文件

Is it possible to write and read from a text file with two programs simultaneously

如果我在 c 或 c++ 中有一个写入特定文本文件的程序和一个从同一文本文件读取的程序,我可以使用这两个吗同时执行程序,以便当第一个程序将新数据写入文本文件时,另一个程序可以读取它并检测到更改?

如有任何帮助,我们将不胜感激。

正在写入文件:

if(fp)
{
    // fp -> handle to the file
    fputs("Satya Pawan Kartik", fp);
    fclose(fp);
}

正在从文件中读取:

for(;;)
{
    // fp -> handle to the file
    while(fgets(line, sizeof line, fp))
    {
        printf("%s\n", line);
    }
}

假设写入文本文件的程序称为write,读取文件的程序称为read

read 显然 运行 永远。执行 write 会显示它对 read 对文本文件所做的更改。如果需要,可以将write永远修改为运行,并通过for loop counter显示其写入的行。 read.

中将明显可见相同的更改

所以是的,可以同时用 2 个程序写入和读取。