I have the above file and would like to output it like this:
jimmy is friends with alice and lives 301.2 miles away.
I would like to extract the double as well and store it in a double variable.
I've tried using getline() and the ignore() function but I can't get it quite right. Any help would be appreciated.
Something like this:
1 2 3 4
string friend1,friend2;
double distance;
cout << friend1 << " is friends with " <<friend2<<" and lives " << distance << "miles away." <<endl;
I'm sorry I wanted to be able to extract the double as well. Sorry for not being clear. I edited the original post, hopefully its a bit more clear as to what I'm trying to do.
Thank you its close to what I want. In my file I have a name "mary beth" and the code you provided only stores "mary" and ignores the rest. Any way to fix this?