What permissions does a file written with fstream have?

Suppose I create a file for writing like this:

std::ofstream my_file("filename", std::ios_base::out | std::ios_base::trunc);

How are the permissions of this file determined? I've had a program running overnight generating files about once a minute - some are 0644 but others are 0660, and there's nothing in my code that should make it change. (I've seen that some implementations allow a third argument to set the file permissions - I'm using gcc 4.1.2 which doesn't appear to support this).


It depends on the umask.

default attrs are set with umask command. it not explains your files attrs changes, but still may be useful for you

Need Your Help

Entity Framewok Code First "ADO.NET provider not found" with local SQL Server CE DLL's

c# .net entity-framework ef-code-first sql-server-ce

I am writing a C# application which uses SQL Server CE 4.0 files, which are accessed through the Entity Framework 6.0 via code-first. (The application needs to be able to use local dll's for the SQL

About exception handling in .NET

.net exception-handling

Suppose there is a .NET application that uses lots of system events and framework methods. I find it hard to manually read the documentation of each event and method to see if they throw exceptions...