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
0

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

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

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

Seen: 17 times

Last updated: Oct 29 '21