LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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, 09: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, 11:15 AM   #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 11:16 AM.
 
Old 10-19-2003, 12: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



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:05 AM.

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
Open Source Consulting | Domain Registration