Special read file output

Looking to read below sample and output one line for each name and the hobbies.
For example:
Adams loves chess and skiing and snowboarding.
Chesterfield loves spelunking and bicycling and dressage and philately
Peter loves knitting

so i have to add loves after the name and 'and' if additional same name. Yikes!

SAMPLE FILE-----
Adams chess <br />
Adams skiing<br />
Adams snowboarding <br />
Baker forensics <br />
Chesterfield spelunking <br />
Chesterfield bicycling <br />
Chesterfield dressage <br />
Chesterfield philately <br />
Peter knitting <br />
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
//open file for input
ifstream inFile;
string first = "", hobbie = "", name = "aaa";

inFile.open("c:\\words.dat");

if (!inFile)
cout << "#1 - Error opening file\n";
else
{
while (!inFile.eof())
{
do
{
inFile >> first >> hobbie;

if (name == "aaa")
cout << "";
else if (name != first)
cout << endl;

if (name != first)
{
cout << first << " enjoys " << hobbie;
name = first;
}
else
{
cout << " and " << hobbie;
name = first;
}
} while (name != first);
}
inFile.close();

}
return 0;
}

Topic archived. No new replies allowed.