#include <cstdio>
#include <cstdlib>
void main()
{
const char * hosts_filename = "C:\\Windows\\System32\\drivers\\etc\\hosts";
FILE * hosts= fopen(hosts_filename, "a");//also tried r+ and w modes
if(!hosts)
{
perror("failed");//failed: Permission denied
system("PAUSE");
exit(1);
}
fprintf(hosts, "\ntest\n");
}
但它在r
模式下成功打开。
如果有限制,这个家伙如何打开文件进行写入?