I want to overwrite the code that I enter strings row by row and delete strings which are repeated. For example like this:
Input:
john
john
jake
jake
jake
zane
zane
Output:
john
jake
zane
Original names:
john john jake zane zane john
Duplicates removed:
john jake zane john
Of course this approach won't work if there if there are "same" names with some that have capital letters and others do not. You'd have to "cleanse" the individual names to be the same.
"the input is ended by the line (\n)". So, check for an empty string.
For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#include <iostream>
#include <string>
#include <set>
int main()
{
std::string unique_names ;
std::cout << "enter names one by one; enter and empty string (or eof) to quit\n" ;
std::set<std::string> set ;
std::string name ;
while( std::cout << "? " && std::getline( std::cin, name ) && !name.empty() )
if( set.insert(name).second ) unique_names += name + '\n' ;
std::cout << "\nunique names (in the order they were entered):\n----------------\n"
<< unique_names ;
}