title: stoi() and stod() are terminating my program, I literally have no clue why
body: <p>I am trying to convert some strings from a file into integers and doubles using <code>stoi()</code> and <code>stod()</code>. However, I keep getting an error which terminated my program.</p>
  
  <p>Here is a screenshot of what happens when I run the code I included below.</p>
  
  <p><img src="https://i.imgur.com/RasBxN3.png" alt=""></p>
  
  <p>The variable <code>ageString</code>, which I am trying to <code>stoi</code>, is = <code>100</code>.</p>
  
  <p>As you can see in the screenshot, it actually converts <code>100</code> into an integer and prints it out. Cool, that's exactly what I want. </p>
  
  <p>But for some reason it is giving me an error saying <code>invalid_argument</code>. How is <code>100</code> an <code>invalid_argument</code> for <code>stoi()</code>?</p>
  
  <p>I already made sure to <code>#include</code> string and to use namespace <code>standard</code>.</p>
  
  <p>I've tried running my code on <code>code::blocks</code> and <code>Repl.it</code> using c++ 11. The results are the same.</p>
  
  <p>I've tried using <code>stoi()</code> on a random number string (not from my file) like <code>1234</code> and it still doesn't work.</p>
  
  <p>My <code>.txt</code> file looks like this (single space):</p>
  
  <pre><code>TEST NAME
  M
  100
  200
  300
  1
  </code></pre>
  
  
  
  <pre><code>//This is the body of my function.
  //I've added several cout statements just to help me debug.
  //In my actual function I don't plan to have any couts.
  
  std::ifstream inputFile;
  inputFile.open(fileName);
  
  std::string name, sex;
  
  int age, activityLevel, calories;
  
  double height, weight;
  
  while(inputFile.good())
  {
      using namespace std;
      string ageString, heightString, weightString, activityString;
  
      getline(inputFile, name, '\n');
      getline(inputFile, sex, '\n'); 
      getline(inputFile, ageString, '\n');
      getline(inputFile, heightString, '\n');
      getline(inputFile, weightString, '\n');
      getline(inputFile, activityString, '\n');
  
      cout &lt;&lt; endl &lt;&lt; name             //All of this prints fine,
           &lt;&lt; endl &lt;&lt; sex              //just like it's written in the file.
           &lt;&lt; endl &lt;&lt; ageString
           &lt;&lt; endl &lt;&lt; heightString
           &lt;&lt; endl &lt;&lt; weightString
           &lt;&lt; endl &lt;&lt; activityString;
  
      cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; stoi(ageString); //This converts and prints
  
      cout &lt;&lt; endl &lt;&lt; endl &lt;&lt; "hello"; //This also prints
  
  }
  
  std::cout &lt;&lt; "run this code"; //The program stops working here.
  inputFile.close();          
  </code></pre>
  
  <p>I expect the code to end by printing <code>run this code</code>, but it actually ends by printing <code>hello</code>.</p>
  
  <p>Error message: </p>
  
  <blockquote>
    <p>terminate called after throwing an instance of 'std::invalid_argument' what(): stoi"</p>
  </blockquote>