[ros-users] bug in operator<< for ros::Time

Troy Straszheim straszheim at willowgarage.com
Wed Sep 28 22:23:12 UTC 2011


Fixed in r15052, note this patch introduces a different bug:  what if my
fill character were '-' before the call to operator<<,  or if field width
were 17.  boost io state savers to the rescue...

On Wed, Sep 28, 2011 at 7:56 AM, Ruben Smits
<ruben.smits at mech.kuleuven.be>wrote:

> Hi,
>
> I noticed that all space created with setw in an ostream gets filled zeros
> after a ros::Time object has been printed in the ostream.
>
> A patch is availble in the following ticket:
> https://code.ros.org/trac/ros/ticket/3693
>
> It just resets the fill caracter to space after the time is printed:
>
> --- time.cpp.original   2011-09-28 16:48:45.000000000 +0200
> +++ time.cpp    2011-09-28 16:41:41.000000000 +0200
> @@ -311,13 +311,13 @@
>
>   std::ostream& operator<<(std::ostream& os, const Time &rhs)
>   {
> -    os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec;
> +    os << rhs.sec << "." << std::setw(9) << std::setfill('0') <<
> rhs.nsec<<std::setfill(' ');
>     return os;
>   }
>
>   std::ostream& operator<<(std::ostream& os, const Duration& rhs)
>   {
> -    os << rhs.sec << "." << std::setw(9) << std::setfill('0') << rhs.nsec;
> +    os << rhs.sec << "." << std::setw(9) << std::setfill('0') <<
> rhs.nsec<<std::setfill(' ');
>     return os;
>   }
>
>
> -- Ruben
> _______________________________________________
> ros-users mailing list
> ros-users at code.ros.org
> https://code.ros.org/mailman/listinfo/ros-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ros.org/pipermail/ros-users/attachments/20110928/dfc52ccd/attachment-0004.html>


More information about the ros-users mailing list