title: Parse integer from std::string, but fail if float
body: <p>In C++ and C there are multiple methods to convert a string to integer, but I haven't found a conversion method that fails on parsing a floating point number.</p>
  
  <pre><code>const float fnum = std::stof("1.5");
  std::cout &lt;&lt; fnum &lt;&lt; std::endl; // prints "1.5", all okay
  
  const int inum = std::stoi("1.5");
  std::cout &lt;&lt; inum &lt;&lt; std::endl; // prints "1", but wrong!
  </code></pre>
  
  <p>I need this to analyse a CSV file for column type. If all fields from one column are integers, then store the column as std::vector&lt; int>, if float, then std::vector&lt; float>, else store it as strings.</p>
  
  <p>The only method that looks promising is this:</p>
  
  <pre><code>std::string num = "1.5";
  char *end = nullptr;
  
  const long lnum = strtol(num.data(), &amp;end, 10);
  if (end != &amp;*num.end()) {
      std::cout &lt;&lt; "Float? " &lt;&lt; l &lt;&lt; " / " &lt;&lt; num &lt;&lt; std::endl;
  } else {
      std::cout &lt;&lt; "Integer! " &lt;&lt; l &lt;&lt; " / " &lt;&lt; num &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>This works, but is quite ugly. Is there a C++-way to solve this?</p>