Ask Your Question
1

ROS_WARN not able to print std::string

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

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";

ROS_WARN(topicNameTrajInput);

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
6

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

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

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

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

Seen: 1,702 times

Last updated: Jan 15 '15