LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 10-19-2003, 10:37 AM   #1
cgifalcon
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;
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.
 
Old 10-19-2003, 12:15 PM   #2
verbal
Member
 
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 )


Verbal

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

Original Poster
Rep: Reputation: 0
Wink

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.
 
  


Reply


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 12:31 PM
not able to get fd of ofstream using stdio_filebuf Devika Linux - General 0 03-28-2005 12:33 AM
ofstream and inheritence phoenix7 Programming 1 01-02-2005 03:52 AM
strange ofstream output maarten Programming 2 09-16-2003 12:42 PM
c++ ofstream -> FILE * ChimpFace9000 Programming 1 08-25-2002 05:58 PM


All times are GMT -5. The time now is 06:47 PM.

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