I want to read an array of integers from a file and publish them on a topic
#
ros::Publisher publisher = nh.advertise<std_msgs::Int32MultiArray>("Topic_1",1);
std_msgs::Int32MultiArray vec;
int i=0;
ifstream infile("array1.txt");
while(infile >> temp)
{
vec[i++] = temp;
// publisher.publish(temp);
}
publisher.publish(vec);
- > #but I'm getting this error after I run the command $catkin_make in my > workspace
#
...
[ 85%] [ 92%] [100%] Built target subscriber
Building CXX object task/CMakeFiles/publisher_1.dir/src/publisher_1.cpp.o
Building CXX object task/CMakeFiles/publisher_2.dir/src/publisher_2.cpp.o
/home/kv/krssg/src/task/src/publisher_1.cpp: In function ‘int main(int, char**)’:
/home/kv/krssg/src/task/src/publisher_1.cpp:27:10: error: no match for ‘operator[]’ (operand types are ‘std_msgs::Int32MultiArray’ and ‘int’)
vec[i++] = temp;
^
/home/kv/krssg/src/task/src/publisher_2.cpp: In function ‘int main(int, char**)’:
/home/kv/krssg/src/task/src/publisher_2.cpp:25:11: error: no match for ‘operator[]’ (operand types are ‘std_msgs::Int32MultiArray’ and ‘int’)
vec2[i++] = temp;
^
make[2]: *** [task/CMakeFiles/publisher_1.dir/src/publisher_1.cpp.o] Error 1
make[1]: *** [task/CMakeFiles/publisher_1.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
make[2]: *** [task/CMakeFiles/publisher_2.dir/src/publisher_2.cpp.o] Error 1
make[1]: *** [task/CMakeFiles/publisher_2.dir/all] Error 2
make: *** [all] Error 2
Invoking "make -j4 -l4" failed