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

Multi-line strings with indentation as input to C++ logging macros

asked 2016-05-06 14:53:11 -0500

spmaniato gravatar image

updated 2016-05-06 14:59:15 -0500

How can I input a multi-line string to one of the C++ logging functions and have it properly ignore the white space? Here's an example:

ROS_INFO("Cost error: %d = \
        (Current: %u - Initial: %u)",
        error_cost, cost, cost_init);

What ends up being printed is a single line (desirable) but with a bunch of spaces (undesirable):

Cost error: 0 =                       (Current: 88 - Initial: 88)

Reading this ( http://stackoverflow.com/a/1135862/26... ) I realized that the backslash takes care of the new line but not the indentation. Is there a better way? (I'd rather not define the string beforehand and then pass a variable to ROS_INFO if I can avoid it.)

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2016-05-06 15:00:07 -0500

ahendrix gravatar image

C/C++ implicitly joins string literals that are adjacent, so you can do:

ROS_INFO("Cost error: %d = "
         "(Current: %u - Initial: %u)",
         error_cost, cost, cost_init);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-06 14:53:11 -0500

Seen: 1,078 times

Last updated: May 06 '16