I have a program that is supposed to read from a file that is asked from the user. Then read names from the file in the form lastname, firstname middlename. Then convert the form to firstname middlename, lastname. Then output it. But I am having trouble. I have to use the find function to locate the ",", then the length function to find the length of the string and finally the substr function to extract the separate names. Here is what I have so far.
#include <iostream>
#include <fstream>
#include <string>
usingnamespace std;
// Named constant definitions (and function declarations):
// Main program:
int main()
{
// Variable declarations:
string fileName, names;
string FirstName, Middlename, Lastname;
// Function body:
cout<<"Please enter a filename you wish to work with."<<endl;
getline(cin,fileName);
ifstream fin(fileName.c_str());
while (!fin){
cout <<"The file did not open."<<endl;
cout <<"Try a different file name."<<endl;
fstream fin(fileName.c_str());
}
getline(fin,names);
while (fin){
strnames.find(,);
Lastname=
}
}
return 0;