The same talker and listener works perfectly with a python file and why it fails to work with a cpp file.
rosrun ros_basic_tutorials talker.cpp
Error
/home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 6: /bin: Is a directory /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 7: listener.cpp: command not found /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 8: */: No such file or directory /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 9: syntax error near unexpected token
(' /home/ishan/catkin_ws/src/ros_basic_tutorials/src/talker.cpp: line 9:
int main(int argc, char **argv)'
talker.cpp
#include "ros/ros.h"
#include "std_msgs/String.h"
#include <sstream>
int main(int argc, char **argv)
{
ros::init(argc, argv, "talker");
ros::NodeHandle n;
ros::Publisher chatter_pub = n.advertise<std_msgs::String>("chatter", 1000);
ros::Rate loop_rate(10);
int count = 0;
while (ros::ok())
{
std_msgs::String msg;
std::stringstream ss;
ss << "hello world " << count;
msg.data = ss.str();
ROS_INFO("%s", msg.data.c_str());
chatter_pub.publish(msg);
ros::spinOnce();
loop_rate.sleep();
++count;
}
return 0;
}
Originally posted by ishaniis on ROS Answers with karma: 1 on 2020-03-22
Post score: 0