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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.