Reading two .dat files for calculating location distance
Stop doing this:

using namespace std;


Yes every text book does this. But once you start writing programs more than 10 lines long it causes issues. Prefix items in the standard namespace with std:: (it was designed to be short). See detailed explanation here: Why is using namespace std considered bad practice

OK. What is the difference between Foodbank and Residence looks like they should simply be a Location class. If in later code you you add differences you can derive from the Location (or better use a location member (prefer composition over inheritance)).

Be consistent (and neat with your spacing).

return os &lt;&lt; r.x  &lt;&lt; "\t"&lt;&lt; r.y&lt;&lt;"\t";
//                     ^^^      ^^^      Hard to read

return os &lt;&lt; r.x  &lt;&lt; "\t" &lt;&lt; r.y &lt;&lt; "\t";


When initializing your arrays. No need to use std::copy. Just use the iterators in the vectors constructor.

vector&lt;Foodbank&gt; foodbankData;
copy(std::istream_iterator&lt;Foodbank&gt;(foodbankFile),
     std::istream_iterator&lt;Foodbank&gt;(),
     std::back_inserter&lt;std::vector&lt;Foodbank&gt;&gt;(foodbankData));


// Can be replaced by a single line:
vector&lt;Foodbank&gt; foodbankData(std::istream_iterator&lt;Foodbank&gt;(foodbankFile),
                              std::istream_iterator&lt;Foodbank&gt;());


Not sure why you are pushing the distance into a long single array. That does not help you work stuff out.

for(auto r:residenceData)
{
    for(auto f:foodbankData)
    {
        //std::cout&lt;&lt;f.x &lt;&lt;", "&lt;&lt;f.y &lt;&lt;", "&lt;&lt;std::endl;
        distances.push_back(distanceCalculate(f.x,f.y,r.x,r.y));
    }
}


I would suspect that what you want is a 2D array. The FoodBanks on the Y axis and the Residences on the X axis (as an example). Then given any Residences  you just need to scan the array vertically to find the closest FoodBank.

std::vector&lt;std::vector&lt;double&gt;&gt;   distance;
for(auto r:residenceData)
{
    distance.push_back(std::vector&lt;double&gt;());

    for(auto f:foodbankData)
    {
        //std::cout&lt;&lt;f.x &lt;&lt;", "&lt;&lt;f.y &lt;&lt;", "&lt;&lt;std::endl;
        distances.back().push_back(distanceCalculate(f.x,f.y,r.x,r.y));
    }
}


Wow thats a lot of parameters

double distanceCalculate(double x1, double y1, double x2, double y2)


If your FoodBank and Residence just inherited from a base of Location (or had a location member) then you can pass location as the start and end point and calculate the distance between them.