473,324 Members | 2,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

ofstream open bit

sam
Hi,

The following C++ line can't pass the c++ compiler:

ofstream omfile;
omfile.open(f, ios::out | ios::trunc, 0700);

In C++, is there anyway I can create a file with the permission bit set
to executable by root?

Sam
Jul 23 '05 #1
5 3383
"sam" <sam++@--.com> wrote in message news:d5***********@news.hgc.com.hk...
ofstream omfile;
omfile.open(f, ios::out | ios::trunc, 0700);

In C++, is there anyway I can create a file with the permission bit set
to executable by root?


There's no way in standard C++ because executable by root is a UNIX concept.
Jul 23 '05 #2
sam
Siemel Naran wrote:
"sam" <sam++@--.com> wrote in message news:d5***********@news.hgc.com.hk...

ofstream omfile;
omfile.open(f, ios::out | ios::trunc, 0700);

In C++, is there anyway I can create a file with the permission bit set
to executable by root?

There's no way in standard C++ because executable by root is a UNIX concept.

Then, I will to use C API to do so.

Sam.
Jul 23 '05 #3
> In C++, is there anyway I can create a file with the permission bit set to
executable by root?


No, not at all. But I would suggest searching your compilers documentation.
They might have a non-standard constructor for ofstream such that you can do
it.

But it is not part of standard C++. It would a be an extension.

Stephen Howe
Jul 23 '05 #4
"sam" <sam++@--.com> wrote in message news:d5***********@news.hgc.com.hk...
Siemel Naran wrote:
"sam" <sam++@--.com> wrote in message news:d5***********@news.hgc.com.hk...
ofstream omfile;
omfile.open(f, ios::out | ios::trunc, 0700);

In C++, is there anyway I can create a file with the permission bit set
to executable by root?


There's no way in standard C++ because executable by root is a UNIX concept.

Then, I will to use C API to do so.


Since "executable by root" is OS specific, perhaps it would be cleaner to separate out the permission setting part; i.e.
open/create your file as per standard C++ and then use the appropriate system() call (chmod or whatever) to set
permissions. That way it is clear to someone reading your code that there is something OS specific going on. Is this
what you meant by "use C API"?

[As an aside, I'm not sure how you'd ascertain the success or otherwise of your system() call... I think the standard
library system() simply returns the status of the *shell* - if such exists - invoked to execute your command].

--
Lionel B

Jul 23 '05 #5
sam
Lionel B wrote:
"sam" <sam++@--.com> wrote in message news:d5***********@news.hgc.com.hk...
Siemel Naran wrote:

"sam" <sam++@--.com> wrote in message news:d5***********@news.hgc.com.hk...
ofstream omfile;
omfile.open(f, ios::out | ios::trunc, 0700);

In C++, is there anyway I can create a file with the permission bit set
to executable by root?

There's no way in standard C++ because executable by root is a UNIX concept.

Then, I will to use C API to do so.

Since "executable by root" is OS specific, perhaps it would be cleaner to separate out the permission setting part; i.e.
open/create your file as per standard C++ and then use the appropriate system() call (chmod or whatever) to set
permissions. That way it is clear to someone reading your code that there is something OS specific going on. Is this
what you meant by "use C API"?

Yeah, this is what I intended to do now. I used popen C API execute the
change of the file permission bit. But I don;t like the idea of use
popen() or exec(). Because I think this should be able do when creating
the file.

However, I must live with it for the time being. Perhas C++ extension
such as ACE_OS might be have a way to do that.

Thanks
Sam

[As an aside, I'm not sure how you'd ascertain the success or otherwise of your system() call... I think the standard
library system() simply returns the status of the *shell* - if such exists - invoked to execute your command].

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: m vaughn | last post by:
I wanted to hold information about open files in a struct and be able pass it around, but the behavior is not what I would expect. Can someone tell me why this doesn't work? (Even better, what is...
1
by: tornado | last post by:
hi all, This is quite puzzling me why is that ofstream constructor is unable to open a file for writing while, a ofstream "open" method can ! The c++ book by Herbert Schildt which i m readin...
1
by: red floyd | last post by:
Is there any way to retrieve the filename given to a std::ofstream (passed in constructor or in ofstream::open())? Or, should I derive from ofstream (should probably be a template to handle...
4
by: Tom Johnson | last post by:
Hi all, I cant believe that Im stuck on such simple code, but I am so... Im trying to open a text file for writing but can never get the file to initially open. Heres what Im having trouble with....
5
by: cpp | last post by:
When I create an instance of ofstream, what is the name of the member variable that holds the filename? For example: ofstream ofs("Output.txt"); cout << ofs.WhatIsThePathVariable; If there...
2
by: Marina | last post by:
I get an "access violation" when I use someting like this: @@@@@@@@@@@@@@ string tempo; const char *output; vector <ofstream> outs(3); .... .... open_output=(const char *)tempo.c_str();...
2
by: slyphiad | last post by:
i'm kinda new at c++ so be patient ^_^ i was just wondering if u guys could help me to solve this problem that i had. i'm trying to create 5 sequential files using ofstream. this is what i...
3
by: jois.de.vivre | last post by:
Hi, I'm trying to write to an ofstream, and for some reason it fails. I know I can check it with fail() or bad(), but it gives me no useful information as to why it fails. Are there any C++...
15
by: keweiming | last post by:
I have a project which needs to open hundreds to thousands of files for writing. The following is a simplified test program I wrote to see if I can use a map<string, ofstream> object to keep the...
5
by: wobudui | last post by:
Hi everyboday, I have some trouble in dealing with the file stream. My souce code Listed hear: int main() { char buffer={0}; ofstream ofile.open("mydata.in",ios::app); ofile.seekp(10);...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.