Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Is there a way i can input people\'s name and last name instead of just one lett

ID: 3635011 • Letter: I

Question

Is there a way i can input people's name and last name instead of just one letter? Please Help. Example, instead of aSet.insert('D'); how can i input something like this aSet.insert('John Doe');


#include <iostream>
#include <set>
/*
using std::cout;
using std::endl;
using std::vector;
*/
using namespace std;


int main()
{

set<char> aSet;

aSet.insert('D');
aSet.insert('A');
aSet.insert('D');
aSet.insert('C');
aSet.insert('C');
aSet.insert('B');

cout << "The set contains:" << endl;
// note const_iterator, not iterator. This iterator cannot be
// used to make changes to the set
set<char>::const_iterator setItr;
for(setItr = aSet.begin(); setItr != aSet.end(); setItr++)
{
cout << *setItr;
}
cout << endl;
return 0;
}

Explanation / Answer

#include <iostream>
#include <set>
/*
using std::cout;
using std::endl;
using std::vector;
*/
using namespace std;


int main()
{

set<string> aSet;

aSet.insert("John Doe");
// changes are shown in red colour

cout << "The set contains:" << endl;
// note const_iterator, not iterator. This iterator cannot be
// used to make changes to the set
set<string>::const_iterator setItr;
for(setItr = aSet.begin(); setItr != aSet.end(); setItr++)
{
cout << *setItr;
}
cout << endl;
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote