LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   ofstream problem (https://www.linuxquestions.org/questions/linux-software-2/ofstream-problem-105896/)

cgifalcon 10-19-2003 09:37 AM

ofstream problem
 
I wrote this code on Linux RedHat9

...
#include <fstream>
...
ifstream file(myfile);

//and all was OK, I was able to read it
//bur when I wrote

...
ofstream file(myfile, ios::app);
if (!file)
cout << "File" << myfile << "could no be opened" << endl;
return 1;
else
...

//the program ended with the message above.

The name of the myfile was the same and the location too.

Could somebody help.

Thank zou very much.

verbal 10-19-2003 11:15 AM

do you have permissions to write to the file?

your first example

std::ifstream infile( some_file )

is essentially the same as:

std::ifstream infile( some_file, std::ios::in ); // read only


but your second:

// append or random access
std::ofstream outfile( some_file, std::ios::app )


Verbal

cgifalcon 10-19-2003 12:00 PM

Thank you very much. I set permission to other and all is OK. I thought that when I logged in as a root and had permission to the file for writting, it was enough.


All times are GMT -5. The time now is 08:23 PM.