Create a new file with group permissions

This seems straightforward enough, but I was not able to determine how I could achieve this in C ++.

I create the file as

ofstream logfile(LOG_FILE, ios::out | ios::app);

The file is created with the following permissions.

-rw-r--r-- 

I really want

-rw-rw-rw- 

For obvious reasons, I do not want to change the umask system for the same.

Thank!

+3
source share
3 answers

Take a look at the chmod call. This is used to change file permissions.

+4
source

There is currently no way to set permissions on files with standard C ++. I suggest you use a system call chmod()or equivalent if it is running on a non-unix OS.

+1
source

mode_t mode = 00777; chmod ( "operation.sh", );

0

All Articles