95 96 97 98 99 100 101 102 103
|
bool searchspace(string key)
{
bool ans = key.find(' ');
if (ans == true)
{
return true;
}
return false;
}
|
The
find member function doesn't return a
bool
indicating whether or not the character was found -- it returns the position of the first occurrence, or
std::string::npos if it wasn't found.
So it should be
1 2 3 4
|
if (key.find(' ') != string::npos)
return true; // We found a space
else
return false;
|
or, more simply,
return key.find(' ') != string::npos;
.
Now, for your other functions:
117 118 119 120 121 122 123 124
|
bool searchuppercase(string key)
{
bool ans = key.find('A' || 'B' || 'C' || 'D' ||
'E' || 'F' || 'G' || 'H' || 'I' ||
'J' || 'K' || 'L' || 'M' || 'N' ||
'O' || 'P' || 'Q' || 'R' || 'S' ||
'T' || 'U' || 'V' || 'W' || 'X' ||
'Y' || 'Z');
|
This part doesn't do what you think it does.
It evaluates
'A' || 'B' || /* ... */ || 'Z'
(which turns out to be
true
since those values are non-zero), and then calls
find with the result.
So you basically get
bool ans = key.find(true);
, or in other words, you're searching for a character whose value is
true
(probably 1 or something).
To fix this, use
find_first_of instead of
find:
1 2 3 4 5
|
string::size_type pos = key.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
if (pos != string::npos)
return true; // We found an uppercase letter
else
return false;
|
(or, more simply, just
return key.find_first_of("ABCDEFGHIJKLMNOPQRSTUVWXYZ") != string::npos;
).
Same with your other functions.
Now, for your
search function, instead of
if (key.find(list[i])>-1)
, I would suggest you write
if (key.find(list[i]) != string::npos)
.
(I think
if (key.find(list[i]) > -1)
will always be
true
anyways, since you're comparing an unsigned integer, which is always positive, with -1.)
600!