Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The function <code>atof()</code> is for converting ASCII (C style strings) to <code>double</code>. You are passing integers; there isn't going to be an overload for that.</p> <p>You can simply use casts (<code>static_cast&lt;double&gt;(arr1[0])</code>, etc), though you might also be able to call the function with the integers. Or you could provide a trivial inline function to do the conversion:</p> <pre><code>inline double itof(int i) { return i; } </code></pre> <hr> <blockquote> <p>I just declared the arrays incorrectly as int instead of string.</p> </blockquote> <p>Careless, but why not declare the arrays as <code>double</code>? And check for array boundaries, too:</p> <pre><code>#include &lt;vector&gt; #include &lt;strstream&gt; #include &lt;string&gt; using namespace std; extern double calculateDistance(double x1, double y1, double x2, double y2, double x3, double y3); double returnDistance(string coord1, string coord2, const vector&lt;string&gt; vec); double returnDistance(string coord1, string coord2, const vector&lt;string&gt;) { vector&lt;double&gt; arr1, arr2; istringstream iss1(coord1); int i1 = 0; while (iss1 &amp;&amp; i1 &lt; 9) // No need to read beyond 9th number iss1 &gt;&gt; arr1[i1++]; istringstream iss2(coord2); int i2 = 0; while (iss2 &amp;&amp; i2 &lt; 9) // No need to read beyond 9th number iss2 &gt;&gt; arr2[i2++]; if (i1 != i2 || i1 &lt; 9) return 0.0; return calculateDistance(arr1[6], arr2[6], arr1[7], arr2[7], arr1[8], arr2[8]); } </code></pre> <p>This compiles cleanly. Note that the <code>const vector&lt;string&gt;</code> argument to the main function is unused and hence unnamed in the function definition.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload