You are here:

C++/file permissions and C++

Advertisement


Question
#include <stdio.h>
#include <iostream.h>

int main(){
fopen("haha.txt","w");
cout << "Content-type: text/html\n\n";
cout << "<html><body>successful";
cout << "</body></html>";
return 0;
}


when i execute the following code online,
the new file that is produced haha.txt's file permission is set as nobody.

is there a way that i can set that permission to the owner of the execution file?

thank you..  

Answer
Hi,
  I am not sure what you intend to do here but try the following bit of code which writes into haha.txt and in this case the file would be owned (writable)by  the owner of the executable.

Regards,
RaiD

#include <stdio.h>
int main(){
FILE * fd = fopen("haha.txt","w");
char * str = "Content-type: text/html\n\n<html><body>successful</body></html>";
fprintf (fd, str);
fclose (fd);
return 0;
}

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


Dharmender Rai

Expertise

I can answer general and system level C/C++ questions.

Experience

I have 5 years of experience in C++.

©2016 About.com. All rights reserved.