Problem loading object data from text file
<p>Why doesn't this code want to load all the values from a text file? It only loads the first object's items correctly but after that it starts going weird. Here is the code:</p>

<pre><code>#include &lt;iostream&gt;
#include &lt;fstream&gt;
#include &lt;cstdlib&gt;

using namespace std;
class Location
{
public:
    Location()
    {
        locName = "No Name";
        locDesc = "No Description";
        locID = 0;
    }

    friend ostream&amp; operator &lt;&lt;(ostream&amp; outs, const Location &amp; showMe)
    {
        // keeping output same as input...
        outs &lt;&lt; showMe.locName &lt;&lt; endl;
        outs &lt;&lt; showMe.locDesc &lt;&lt; endl;
        outs &lt;&lt; showMe.locID &lt;&lt; endl;

        return outs;
    }

    friend istream&amp; operator &gt;&gt;(istream&amp; ins, Location &amp; inLoc)
    {
        getline(ins, inLoc.locName);
        getline(ins, inLoc.locDesc);
        ins &gt;&gt; inLoc.locID;

        return ins;
    }

private:
    string locName;
    string locDesc;
    int locID;
};

int main()
{
    ifstream inFile;

    inFile.open("loc_data.txt");
    if (inFile.fail())
        {
            cout &lt;&lt; "\nCould not open the input file!";
            exit(1);
        }

    Location fileLoc[10];
    int i = 0;

    while (inFile.good())
        {
            inFile &gt;&gt; fileLoc[i];
            i++;
        }

    for (int j = 0; j &lt; 10; j++)
        cout &lt;&lt; fileLoc[j];

    return 0;
}
</code></pre>

<p>The input file is: </p>

<pre><code>Town Hall
Main venue for functions
1
City Park
Outdoor venue
2
Train Station
Commuting point
3
Local Airport
Long distance travel
4
</code></pre>

<p>And the output is:</p>

<pre><code>Town Hall
Main venue for functions
1

City Park
0
No Name
No Description
0
No Name
No Description
0
No Name
No Description
0
No Name
No Description
0
No Name
No Description
0
No Name
No Description
0
No Name
No Description
0
No Name
No Description
0
</code></pre>

<p>I have a suspucion that getline is responsible for this but do not know enough to be sure, however I would really like to know why this is happening and not just a 'fix'.</p>
