In writing a logger for an application, the datestamp ends up adding a new line.
The datestamp function is as follows:

string log_class::get_time() {
	time_t rawtime;
	time (&rawtime);
	string timestamp;
	timestamp = (ctime (&rawtime));
	return timestamp;

This outputs something like Tue Sep 6 14:58:35 2011 , but when called in the main function with logfile << get_time() << " " << logmessage_to_write << endl; , it produces a newline after the datestamp like:

Tue Sep  6 14:58:35 2011
 data goes here

I would like it to be on one line, as in Tue Sep 6 14:58:35 2011 data goes here , but I can't figure out how to do this. If anyone has an idea how to remove the newline, that would be great.

6 Years
Discussion Span
Last Post by NathanOliver

it erases the last element in the string which happens to be the newline. here is a good reference for working with strings.

Edited by NathanOliver: n/a


Okay, that makes sense. One last question: Do you know how to format the time into something like yyyy-mm-dd hh:mm:ss? This is for a log function and it will make it easier to go through the log.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.