Check out example codes for "roscpp publish int32". It will help you in understanding the concepts better.

Code Example 1

#include <std_msgs/Int8.h>

std_msgs::Int8 msg;
msg.data = 17;
ROS_INFO("%d", msg.data);
chatter_pub.publish(msg);

Learn ReactJs, React Native from akashmittal.com