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

Ruben Smits ruben.smits at mech.kuleuven.be
Wed Sep 28 14:56:23 UTC 2011


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



More information about the ros-users mailing list