![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Professional Programmer
|
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:
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! ▄▄▄▄ |
|
|
|
|
|
|
#2 |
|
The Oblivious One
Join Date: May 2005
Location: Ontario, Canada
Posts: 648
Rep Power: 4
![]() |
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! |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Dec 2005
Posts: 53
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#4 | |
|
Professional Programmer
|
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:
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! ▄▄▄▄ |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|