title: I want to store in an array messages from a ROS topic for further elaboration
body: <p>I'm sorry if this question is too simple for you, but i don't have good programming skills and ROS knowledge. I have a ROS topic in which are published some numbers that are heart beat intervals in seconds. I need to subscribe to that topic and do this kind of elaboration: The idea is to have a little array of ten numbers in which i can store continuously ten heart beat. Then i have a bigger array of 60 numbers that must go up by ten position in order to have at the bottom the newest ten values of the small array and it has to "throw away" the ten oldest values ( i did a bit of research and maybe i have to use a vector instead of an array because in C++ array are fixed as far as i read ). Then i have to print every time these 60 values in a text file (i mean in a loop, so the the text file will be continuously overwritten). Moreover, i see that ROS outputs the data from a topic in this manner: <code>data: 0.987</code> with every data divided from the others by <code>---</code> in a column. What i really want, because i need it for a script that reads text file in this manner, is a text file in which the values are in one column without spaces and other signs or words, like this:</p>
  
  <pre><code>0.404
  0.952
  0.956
  0.940
  0.960
  </code></pre>
  
  <p>I provide below the code for my node, in which, for now, i did only the subscribing part, since i have no idea on how to do the things that i have to do later. Thank you in advance for your help!!!</p>
  
  <p>Code:</p>
  
  <pre><code>#include "ros/ros.h"
  #include "std_msgs/String.h"
  #include "../include/heart_rate_monitor/wfdb.h"
  #include &lt;stdio.h&gt;
  #include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  #include &lt;algorithm&gt;
  #include &lt;vector&gt;
  
  int main(int argc, char **argv)
  {
  
  ros::init(argc, argv, "writer");
  
  
  ros::NodeHandle n;
  
  
  ros::Subscriber sub = n.subscribe("/HeartRateInterval", 1000);
  
  
  ros::spin();
  
  return 0;
  }
  </code></pre>
  
  <p>NOTE: I didn't include the Float32/64 header because i publish the heart beats as a string. I don't know if this is of interest.</p>
  
  <p>EDIT: I will include below the code of the publisher node which publish on the ROS topic the data.</p>
  
  <pre><code>#include "ros/ros.h"
  #include "std_msgs/String.h"
  #include "../include/heart_rate_monitor/wfdb.h"
  #include &lt;stdio.h&gt;
  #include &lt;sstream&gt;
  #include &lt;iostream&gt;
  #include &lt;fstream&gt;
  #include &lt;iomanip&gt;
  
  using namespace std;
  
  
  int main(int argc, char **argv)
  {
  
  ros::init(argc, argv, "heart_rate_monitor");
  
  ros::NodeHandle n;
  
  ros::Publisher pub = n.advertise&lt;std_msgs::String&gt;("/HeartRateInterval", 1000);
  
  ros::Rate loop_rate(1);
  
  while (ros::ok())
  
  { 
  
  ifstream inputFile("/home/marco/Scrivania/marks.txt");
  
  string line;
  
  while (getline(inputFile, line)) {
  
  
  istringstream ss(line);
  
  string heart;
  
  ss &gt;&gt; heart;
  
  std_msgs::String msg;
  
  msg.data = ss.str();
  
  pub.publish(msg);
  
  ros::spinOnce();
  
  loop_rate.sleep();
  
  }
  
  }
  
  return 0;
  
  }
  </code></pre>
  
  <p>Since what is published is the "variable" <code>msg</code>, i tried to replace in the code given as an answer the variable <code>string_msg</code> with <code>msg</code>, but nothing has changed. Thank you!</p>