title: Function is causing a segmentation fault only when you press enter or it reaches the end of a file
body: <p>This function is a work in progress and is designed to read data from stdin for a simple integer calculator. The function works as intended when entering an operator and two operands: + 2 2. It also correctly reads from a file with similar formatting piped in on the command line. Despite this it will segfualt if the user hits enter on the command line or it reaches the end of a file. I'm not sure where I've gone wrong? What could be causing this behavior?</p>
  
  <pre><code>void process_input ()
  {
  
  while(!std::cin.eof())
  {
      std::string line;
      std::string n;
  
  
      getline(std::cin, line);
  
  
      if (std::cin.fail())
          break;
      else if (line == "quit")
          return;
  
      std::istringstream stream(line);
      std::vector&lt;std::string&gt; input_cpy(0);
      while (stream &gt;&gt; n)
          input_cpy.push_back(n);
  
      //Clear global_input_cpy on each iteration and load the new line into it
      global_input_cpy.clear();
      for (int i = 0; i &lt; input_cpy.size(); ++i)
          global_input_cpy.push_back(input_cpy[i]);
  
  
  
      if(input_cpy[0] == "+")
          sum(std::stol(input_cpy[1]), std::stol(input_cpy[2]));
      else if (input_cpy[0] == "*")
          multiply(std::stol(input_cpy[1]), std::stol(input_cpy[2]));
      else if (input_cpy[0] == "^")
          exponent(std::stol(input_cpy[1]), std::stol(input_cpy[2]));
      else
          std::cout &lt;&lt; "input '" &lt;&lt; input_cpy[0] &lt;&lt; "'" &lt;&lt; " unrecognized. skipping." &lt;&lt; "\n";
  
      input_cpy.clear();
  }
  }
  </code></pre>