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

Cannot ouput string service via ROS_INFO

asked 2012-11-24 16:45:01 -0600

kbedolla gravatar image

I have a service of type string, my server simply responds with a string. I am trying to implement my client to simply call the service and ROS_INFO out the response. However, when I try to compile I get an error on the line where I am doing the ROS_INFO output. The error is:

error: cannot pass objects of non-trivially-copyable type ‘struct std::basic_string<char>’ through ‘...’

Here is my code:

parallax_eddie_robot::get_version srv;





I don't know why it thinks my service is returning a struct because my service file (myservice.srv) is only for a string. It looks like this:

string version

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2012-11-24 17:40:32 -0600

Eric Perko gravatar image

In a nutshell, changing your print to ROS_INFO("%s", srv.response.version.c_str()) should fix your compile error.

A string type in a ROS message/service maps to a std::string in C++ (see the msg package for more details). std::string's are not printable with something like printf, unless you get access to the underlying const char* data which is what printf's "%s" format string is expecting. You can get access to the C-string via the c_str() member on std::string.

edit flag offensive delete link more


Thank you!

kbedolla gravatar image kbedolla  ( 2012-11-24 17:53:06 -0600 )edit

You can also use the C++ stream interface if you like: ROS_INFO_STREAM(srv.response.version)

joq gravatar image joq  ( 2012-11-26 04:58:35 -0600 )edit

Question Tools


Asked: 2012-11-24 16:45:01 -0600

Seen: 11,808 times

Last updated: Nov 24 '12