|
#1
|
|||
|
|||
|
chmod
Hello everyone,
Can someone please tell me whether there is the equivalent of chmod in Standard C++, i.e. change permissions on a file ? I don't really want to use the system command ? I found that I can do :- char fn[]="./temp.file"; FILE *stream; if ((stream = fopen(fn, "w")) != NULL) { if (chmod(fn, S_IRGRP|S_IRWXU|S_IROTH ) != 0) { perror("chmod() error"); } fclose(stream); } But the issue here is that I need to use the old fashioned way of reading a file line by line, rather than use fstream. Can I cast from std::fstream to const char* ? Many thanks. Last edited by ami; 10-22-2009 at 08:03 AM. |
|
#2
|
|||
|
|||
|
I do not really understand your question:
- chmod as you have it does not care what file type you used, it is operating off the file name! -you did not use fstream, you used a FILE* If you want to read a text file line by line, use ifstream and getline. Or read the entire file into a buffer if its small and split it up using string functions, based off the end of line markers. You cannot convert from a file object to a char * safely and expect the char * to contain the file's data. You can read the whole file into an allocated char * or array. Or part of the file, all the way down to 1 char into a char variable. Try again, what exactly are you wanting to do? Here is how to read line by line: ifstream ifs; ifs.open(fn); ifs.getline(buffer, max_length); //buffer is a char* or unsigned char* you can use it directly, or poke it into a string, or you can read directly into a string variable (I am fairly sure). |
|
#3
|
||||
|
||||
|
There's no equivalent of chmod in standard C++. However, chmod is rather portable function. If and when the FleSystem library is added to standard C++ is hard to tell at this stage (it won't happpen in C++0x).
__________________
Danny Kalev |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| PHP upload question | leafdodger | Web | 2 | 12-12-2006 09:41 AM |