title: Segmentation fault (core dumped) Error
body: <p>My program compiles fines but upon inputting a file I get a "Segmentation fault (core dumped)" error. Am I not handling the ostream correctly?</p>
  
  <pre><code>#include &lt;std_lib_facilities.h&gt;
  
  struct Reading {
      int hour;
      double temperature;
      Reading(int h, double t): hour(h), temperature(t) { }
      bool operator&lt;(const Reading &amp;r) const;
  };
  
  bool Reading::operator&lt;(const Reading &amp;r) const
  {
  // stub version                                                                                         
  
      if (temperature &lt; r.temperature){
  
          return true;
  
  }
      else if (r.temperature &lt; temperature)  {
  
          return false;
      }
  
  
  }
  
  /*                                                                                                      
   * function declarations                                                                                
   */
  
  ostream&amp; operator&lt;&lt;(ostream&amp; ost, const Reading &amp;r);
  
  vector&lt;Reading&gt; get_temps();
  
  double check_adjust_temp(double temperature, char scale);
  
  double c_to_f(double temperature);
  
  double mean(vector&lt;Reading&gt; temps);
  
  double median(vector&lt;Reading&gt; temps);
  
  void print_results(const vector&lt;Reading&gt;&amp; temps, double mean_temp,
                     double median_temp);
  
  int main()
      try
          {
              vector&lt;Reading&gt; temps = get_temps();
              if (temps.size() == 0) error("no temperatures given!");
              double mean_temp = mean(temps);
              sort(temps.begin(), temps.end());
              double median_temp = median(temps);
              print_results(temps, mean_temp, median_temp);
          }
      catch (exception&amp; e) {
          cerr &lt;&lt; "error: " &lt;&lt; e.what() &lt;&lt; '\n';
          return 1;
      }
      catch (...) {
          cerr &lt;&lt; "Oops: unknown exception!\n";
          return 2;
      }
  
  /*                                                                                                      
   * function definitions                                                                                 
   */
  
  ostream&amp; operator&lt;&lt;(ostream&amp; ost, const Reading &amp;r)
  {
  
      return ost &lt;&lt; '(' &lt;&lt; r.hour
                 &lt;&lt; ',' &lt;&lt; r.temperature &lt;&lt;')';
  }
  
  vector&lt;Reading&gt; get_temps()
  {
      cout &lt;&lt; "Please enter name of input file name: ";
      string name;;
      cin &gt;&gt; name;
      ifstream ist(name.c_str());
      if(!ist) error("can't open input file ", name);
  
      vector&lt;Reading&gt; temps;
      int hour;
      double temperature;
      while (ist &gt;&gt; hour &gt;&gt; temperature){
          if (hour &lt;0 || 23 &lt;hour) error("hour out of range");
          temps.push_back( Reading(hour,temperature));
      }
  
  }
  
  double check_adjust_temp(double temperature, char scale)
  {
      if (scale == 'c' || 'C'){
  
          return c_to_f(temperature);
      }
      else if (scale == 'f' || 'F')  {
  
          return temperature;
      }
      else {
  
          error("Wrong input type");
      }
  }
  
  double c_to_f(double temperature)
  {
      double c;
      c = ((temperature * (9.0/5)) + 32);
      return (c);
  }
  
  double mean(vector&lt;Reading&gt; temps)
  {
      double mean_temp;
      double sum = 0;
      for (int i = 0; i&lt; temps.size(); ++i) sum += temps[i].temperature;
      mean_temp = sum/temps.size();
      return (mean_temp);
  }
  
  double median(vector&lt;Reading&gt; temps)
  {
      double median_temp;
      sort (temps.begin(), temps.end());
      median_temp = temps[temps.size()/2].temperature;
      return (median_temp);
  }
  
  void print_results(const vector&lt;Reading&gt;&amp; temps, double mean_temp,
                     double median_temp)
  {
  
      cout &lt;&lt; "The sorted temperatures are:\n";
      cout &lt;&lt; get_temps;
      cout &lt;&lt; "The mean temperature is " &lt;&lt; mean_temp &lt;&lt; ".\n";
      cout &lt;&lt; "The median temperature is " &lt;&lt; median_temp &lt;&lt; ".\n";
  }
  </code></pre>