Parse -0 string as -0.0f
<p>I'm learning C++ using Visual Studio 2015.</p><p>I have this method:</p><pre><br /><code>double ConvertDegreesToDecimal(std::string value)<br />{<br /> using namespace std;<br /> vector<float> values;<br /> string item;<br /><br /> istringstream in(value);<br /><br /> while (getline(in, item, ' '))<br /> values.push_back(atof(item.c_str()));<br /><br /> DegreesCoordinate* coord = new DegreesCoordinate((short)values[0], (unsigned char)values[1], (double)values[2], NotSet);<br /><br /> return DegreesConverter::convertDegressToDecimal(coord);<br />}<br /></code><br /></pre><p>It works fine with all cases except with this one: <code>-0 17 25</code>. This number is a coordinate in degrees <code>-0 degrees 17 minutes 25 seconds</code>.</p><p>I have thought to check inside <code>while (getline(in, item, ' '))</code> if item is <code>-0</code> and then multiply <code>atof(item.c_str())</code> by <code>-1</code>. But, what happens if item is <code>-00</code> or <code>-000</code>.</p><p>Do you know a better approach to parse a negative zero?</p><br /><h2>Click here view more answers <a href="%20http://stackoverflow.com/questions/34526215/parse-0-string-as-0-0f">http://ift.tt/1Jfjfzl</a></h2>
Nhận xét
Đăng nhận xét