Keep the blacklist in a vector of strings, then use a loop to compare the name entered by the user to each of the names in the blacklist.
vector<string> blacklist;
If you want to ignore case, then convert all names to either upper or lower case, whichever you want, so that you can make case insensitive comparisons easier. There is no function that converts entire strings, so you have to loop through the string one character at a time and convert them using either toupper() or tolower()
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343
The best thing to use is std::map here. That will give you very good performance.
Here is an example :
#include <iostream>
#include <map>
#include <string>
using namespace std;
typedef pair<string,int> NamePair;
int main(){
std::map<string,int> listOfNames;
listOfNames.insert( NamePair("jeff",0) );
listOfNames.insert( NamePair("Don",1) );
listOfNames.insert( NamePair("Calvin",2) );
//or read from a file with names and insert it into the map
string input;
cin >> input;
if(listOfNames.find(input) != listOfNames.end()){
cout << "Found in list\n";
}
else cout << input << " is not in my list\n";
}
You could read from a file that contains names, and insert it into the listOfNames,
then use that for guidance. Here is some reference
for std::map.
firstPerson
Senior Poster
3,923 posts since Dec 2008
Reputation Points: 841
Solved Threads: 608