470,870 Members | 996 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

asctime without trailing newline character

Hello, all. I am writing a patch of code that displays the time and date in the middle of the line. I am using the asctime function from ctime but I don't want the trailing newline character after the execution.

Is there any way to remove it, or should I go about finding the time using a different method?

Expand|Select|Wrap|Line Numbers
  1. ostream &td(ostream &stream)
  2. {
  3.   time_t t;
  5.   t = time(NULL);
  6.   stream << asctime(localtime(&t));
  8.   return stream;
  9. }
Dec 28 '07 #1
1 11639
9,208 Expert Mod 8TB
asctime returns a C-style string. The \n is the byte before the \0. Just change the \n byte to \0 and off you go.
Dec 28 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

30 posts views Thread by Martin Bless | last post: by
4 posts views Thread by fowlertrainer | last post: by
14 posts views Thread by Marcin Ciura | last post: by
4 posts views Thread by Till Crueger | last post: by
29 posts views Thread by runningdog | last post: by
5 posts views Thread by Adam Right | last post: by
4 posts views Thread by lihao0129 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.