ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Use ROS_ info to output std::vector data

asked 2021-10-28 13:01:57 -0500

rhw0023 gravatar image

If I'm dealing with std::vector data in C++ and I'd like to print it on the output stream I can do something similar to what is shown below:

std::cout << "Data Retrieved: \n";
std::copy(data.begin(), data.end(), std::ostream_iterator<double>(std::cout, " "));
std::cout << std::endl;

How might I reproduce this behavior using ROS_INFO to display the data on the console as new data is received?

Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2021-10-29 09:18:21 -0500

It should be easy to use a std::stringstream to accomplish what you want. Moreover, it might be a bit cleaner to use ROS_INFO_STREAM for this particular application. Something like this:

  std::stringstream ss;
  ss << "Data Retrieved: \n";
  std::copy(data.begin(), data.end(), std::ostream_iterator<double>(ss, " "));
  ss << std::endl;
edit flag offensive delete link more


This worked out great! Thank you!

rhw0023 gravatar image rhw0023  ( 2021-10-29 10:30:39 -0500 )edit

Question Tools


Asked: 2021-10-28 13:01:57 -0500

Seen: 727 times

Last updated: Oct 29 '21