Reading text file

I'm trying to arrange names alphabetically from a textfile. Inside my textfile, it's like : "John", "Edward", "Peaches", "Anna"... etc.(It has thousand more names, all with quotations, separated by comma and I think it's not typed line by line... but using only one line). How can I read each name separately?

this code, it works if the textfile contains names seperated by lines and without commas and quotations. I do not know with the case I've stated above. Help? Thank you!

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
    string numbers[1000];
    string line;
    string number;
    string y;
    string x;
    int z = 1;
    ifstream myfile;
    myfile.open("names.txt");
    while(myfile.good())
    {
        getline(myfile, line);
        x = line;
        numbers[z]=x;
        z++;
    }
    for(int p=0; p<=1000; p++)
    {
        for(int r=0; r<1000; r++)
        {
            if(numbers[r]>numbers[p])
            {
                y=numbers[r];
                numbers[r]=numbers[p];
                numbers[p]=y;
            }
        }
    }
    for(int i=0; i<1000; i++)

    {
        cout << numbers[i] << endl;
    }


This only shows the data inside text file.
I'm really sorry for the bad code. I'm new in c++.
getline has a delimiter option.

getline ( file, value, ',' );
Woah, thank you so much! :)))
Topic archived. No new replies allowed.