I am having trouble with reading in a text file full of names (some are repeated) and inputting the first and last names together on 1 line. The program works and deletes repeated names but outputs them in alphabetical order with first and last names being treated as 2 different names. Am I outputting the names wrong with:

```
string name;
while (partyList >> name)
{
    NamesList.insert(name);
}

cout << "Here is the party list without repetion: " << endl;
while (!NamesList.empty())                                                  {
    cout << ' ' << *NamesList.begin() << endl;
    NamesList.erase(NamesList.begin());
}

```

?

The text file is PartyList.txt and it contains:

```
Daniel Walrus
Amy Giester
Jim Carry
Gregg Lunch
Irony Max
Jim Carry
Daniel Walrus          
Gregg Lunch

```

Currently my output is:

```
Amy 
Carrey
Daniel
Giester
Gregg
Irony
Jim
Lunch
Max
Walrus

```

Here is my code (this is part of a larger assignment which is completed besides making the first and last names go together):

```
#include <iostream>
#include <fstream>
#include <string>
#include <set>

using namespace std;
void PartyList();

int main()
{
PartyList();
system("PAUSE");
return 0;
}

void PartyList()
{
fstream partyList;
partyList.open("PartyList.txt", fstream::in);

if (!partyList)
{
    cout << "Couldn't open file!" << endl;
}

set<string> NamesList;
string name;
while (partyList >> name)
{
    NamesList.insert(name);
}

cout << "Here is the party list without repetion: " << endl;                    
while(!NamesList.empty())                                                   {                                                                               cout << ' ' << *NamesList.begin() << endl;                                  
    NamesList.erase(NamesList.begin());
}
//cout << name << endl;

cout << endl;
}

```
['https://Stackoverflow.com/questions/30072278', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/4110090/']
The `>>` operator in `partyList >> name` only reads from `partyList` until whitespace, which includes spaces, so `name` gets the values `"Daniel"`, `"Walrus"`, `"Amy"`, etc. on iteration. If you want to read one line at a time, use

```
while (std::getline(partyList, name))

```

which gets you `"Daniel Walrus"` etc.
```
while (partyList >> name)

```

The `>>` operator is looking here for a first blank character. That's why your names are split this way.