You could also just do this:
ofstream out;out.open("test.txt");out.close();//attrib [parameters] [file]//+R -> readonly//+H -> hidden//+S -> system file (ultra hidden)//There are more, type 'attrib /?' in cmd to find all of the optionssystem("attrib +R test.txt");
And that's it! Let me know if you have any questions.
EDIT
This only works on Windows, as it uses a direct console command.