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

ROS_WARN not able to print std::string

asked 2015-01-15 04:29:33 -0600

fabbro gravatar image

Dear All,

I want to print in a ROS WARNING a string. But I am not able to do that.

Someone of you could help me please?

What I am doing is the following:

std::string topicNameTrajInput ="TopicRos";


Any ideas why this doesn't work? Thanks a lot.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2015-01-15 06:25:09 -0600

Wolf gravatar image

ROS_WARN behaves like printf so for a std::string it'd be something like:

ROS_WARN( "%s", topicNameTrajInput.c_str() ); // (Format string and args for the format string)

I'd suggest use use the easier ROS_WARM_STREAM for a std::string, it behaves like std::cout, e. g.:

ROS_WARN_STREAM( topicNameTrajInput );

or with << operator and multiple args :

ROS_WARN_STREAM( topicNameTrajInput << " Hello world " << 1000 );
edit flag offensive delete link more

Question Tools

1 follower


Asked: 2015-01-15 04:29:33 -0600

Seen: 4,813 times

Last updated: Jan 15 '15