title: c++: Accessing the Elements of a Map of Strings and Boost Circular Buffers
body: <p>I'm writing a program that reads a text file of city names into a vector, then uses a stl::map to associate each city with a boost circular buffer. I also have a vector of temperature data, which I converted to double type after reading it as strings from another text file. I want to know how to feed this data into a circular buffer of my choosing. For example, the temperature data is from Boston, so I want to put it into the circular buffer associated with Boston. If someone could show me how to do this I would really appreciate it! Here's my code. The code having to do with maps is near the bottom.</p>
  
  <pre><code>#include &lt; map &gt;
  #include &lt; algorithm &gt;
  #include &lt; cstdlib &gt;
  #include &lt; fstream &gt;
  #include &lt; iostream &gt;
  #include &lt; iterator &gt;
  #include &lt; stdexcept &gt;
  #include &lt; string &gt;
  #include &lt; sstream &gt;
  #include &lt; vector &gt;
  #include &lt; utility &gt;
  #include &lt; boost/circular_buffer.hpp &gt;
  
  double StrToDouble(std::string const&amp; s) // a function to convert string vectors to double.
  {
      std::istringstream iss(s);
      double value;
  
      if (!(iss &gt;&gt; value)) throw std::runtime_error("invalid double");
  
      return value;
  }
  
  using namespace std;
  
  int main()
  {
  
      std::fstream fileone("tempdata.txt"); // reading the temperature data into a vector.
  
      std::string x;
  
      vector&lt;string&gt; datastring (0);
  
      while (getline(fileone, x))
      {
          datastring.push_back(x);
      }
  
      vector&lt;double&gt;datadouble;
  
      std::transform(datastring.begin(), datastring.end(), std::back_inserter(datadouble), StrToDouble); // converting it to double using the function
  
  
  
      std::fstream filetwo("cities.txt"); // reading the cities into a vector.
  
      std::string y;
  
      vector&lt;string&gt; cities (0);
  
      while (getline(filetwo, y))
      {
          cities.push_back(y);
      }
  
      map&lt;string,boost::circular_buffer&lt;double&gt;*&gt; cities_and_temps; // creating a map to associate each city with a circular buffer.
  
      for (unsigned int i = 0; i &lt; cities.size(); i++)
      {
          cities_and_temps.insert(make_pair(cities.at(i), new boost::circular_buffer&lt;double&gt;(32)));
      }
  
      return 0;
  }
  </code></pre>