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

Revision history [back]

When printing an std::string (using the %s specifier), you need to actually print the underlying C string and not the std::string object. Otherwise you will get "garbage" like that.

You can do this by calling the c_str() method of the std::string object. I actually just tested and you should be getting a compiler warning if you don't do that.

In your case, this would look like:

RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "sending back response: [%s]", response.get()->concatinated_aa_bb.c_str());

Same thing for the other times you use RCLCPP_INFO with std::string objects. Just add .c_str() after all std::string variables to print them.

When printing an std::string (using the %s specifier), you need to actually print the underlying C string and not the std::string object. Otherwise you will get "garbage" like that.that. This is a very common error with the printf functions too. For example: https://stackoverflow.com/questions/7769715/c-and-printf-strange-character-output

You can do this by calling the c_str() method of the std::string object. I actually just tested and you should be getting a compiler warning if you don't do that.

In your case, this would look like:

RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "sending back response: [%s]", response.get()->concatinated_aa_bb.c_str());

Same thing for the other times you use RCLCPP_INFO with std::string objects. Just add .c_str() after all std::string variables to print them.

When printing an std::string (using the %s specifier), you need to actually print the underlying C string and not the std::string object. Otherwise you will get "garbage" like that. This is a very common error with the printf functions too. (and RCLCPP_INFO does pretty much the same thing underneath). For example: https://stackoverflow.com/questions/7769715/c-and-printf-strange-character-output

You can do this by calling the c_str() method of the std::string object. I actually just tested and you should be getting a compiler warning if you don't do that.

In your case, this would look like:

RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "sending back response: [%s]", response.get()->concatinated_aa_bb.c_str());

Same thing for the other times you use RCLCPP_INFO with std::string objects. Just add .c_str() after all std::string variables to print them.

When printing an std::string (using the %s specifier), you need to actually print the underlying C string and not the std::string object. Otherwise you will get "garbage" like that. This is a very common error with the printf functions (and RCLCPP_INFO does pretty much the same thing underneath). For example: https://stackoverflow.com/questions/7769715/c-and-printf-strange-character-output

You can do this by calling the c_str() method of the std::string object. I actually just tested and you should be getting a compiler warning if you don't do that.that. If you did get warnings when compiling, don't ignore them!

In your case, this would look like:

RCLCPP_INFO(rclcpp::get_logger("rclcpp"), "sending back response: [%s]", response.get()->concatinated_aa_bb.c_str());

Same thing for the other times you use RCLCPP_INFO with std::string objects. Just add .c_str() after all std::string variables to print them.