find function in program

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <iostream>
#include <fstream>
#include <string>
using namespace 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;
what does the input file look like ?
Topic archived. No new replies allowed.