Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jan 15th, 2006, 5:58 PM   #1
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
Fstream logging

I am trying to figure out how to log data to a plain text file with this code:
  ofstream myfile;
  logfile.open ("test.txt");
  logfile << "Message from " << inet_ntoa(remote_address.sin_addr) << ": " << message << endl;
  logfile.close();

Except the log is overwritten each time this executes. I know it's something simple, but i can't find it. I'm going to continue to look now..
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Old Jan 15th, 2006, 6:13 PM   #2
Jessehk
The Oblivious One
 
Jessehk's Avatar
 
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4 Jessehk is on a distinguished road
I think it's something like std::ios::app or something...

Sorry, I haven't done a lot of file input/output.
__________________
Dr. Zoidberg: [ecstatic] I'm going to a movie... with FRIENDS!
Jessehk is offline   Reply With Quote
Old Jan 15th, 2006, 6:13 PM   #3
Jason Isom
Programmer
 
Join Date: Dec 2005
Posts: 53
Rep Power: 3 Jason Isom is on a distinguished road
Try:

  ofstream myfile;
  logfile.open ("test.txt", ofstream::app);
  logfile << "Message from " << inet_ntoa(remote_address.sin_addr) << ": " << message << endl;
  logfile.close();

ofstream::app stands for append.
Jason Isom is offline   Reply With Quote
Old Jan 15th, 2006, 6:16 PM   #4
jayme
Professional Programmer
 
jayme's Avatar
 
Join Date: Nov 2005
Location: Canada
Posts: 495
Rep Power: 0 jayme is an unknown quantity at this point
Send a message via MSN to jayme
  ofstream myfile; //error, change to logfile
  logfile.open ("test.txt", ofstream::app);
  logfile << "Message from " << inet_ntoa(remote_address.sin_addr) << ": " << message << endl;
  logfile.close();

hehe, ya.. i was having an error with that, looks like it wasn't only me who made the mistake though . Thanks
__________________

Quote:
Originally Posted by Mohamed Jihad
Durka durka!
Due to incorrect calculations during the middle ages, our calendar actually begins a few years after Jesus' birth. Thus the real 6/6/6 happened a few years back. The world already ended and you missed it.

Download Code::Blocks now!
jayme is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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 On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:49 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC