Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 10-19-2003, 09:37 AM   #1
LQ Newbie
Registered: Oct 2003
Posts: 9

Rep: Reputation: 0
Angry 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;

//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.
Old 10-19-2003, 11:15 AM   #2
Registered: Jul 2002
Location: New York
Distribution: Red Hat 7.2, SuSE 7.3
Posts: 60

Rep: Reputation: 15
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 )


Last edited by verbal; 10-19-2003 at 11:16 AM.
Old 10-19-2003, 12:00 PM   #3
LQ Newbie
Registered: Oct 2003
Posts: 9

Original Poster
Rep: Reputation: 0

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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems with ifstream/ofstream kornerr Programming 2 07-04-2005 11:31 AM
not able to get fd of ofstream using stdio_filebuf Devika Linux - General 0 03-27-2005 11:33 PM
ofstream and inheritence phoenix7 Programming 1 01-02-2005 02:52 AM
strange ofstream output maarten Programming 2 09-16-2003 11:42 AM
c++ ofstream -> FILE * ChimpFace9000 Programming 1 08-25-2002 04:58 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:56 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration