I use ios::out if file is not created before, it will create file.txt for us
You missed the point. That is not what that line of code does.
It adds NGOC to the file every time you run the program, and I don't think that is your intent. Your code will create the file without that, it will just be empty.