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

Use ROS_ info to output std::vector data

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

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
2

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

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;
  ROS_INFO_STREAM(ss.str());
edit flag offensive delete link more

Comments

This worked out great! Thank you!

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

Question Tools

Stats

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

Seen: 875 times

Last updated: Oct 29 '21