View Full Version : need quick c++ help PLZ

09-06-01, 09:52 PM
its 9:30 right now..

i need some help on creating an isavalid function in c++

i want this to be a boolean statement look at a letter and see if it is contained in a seperate string of letters. If not then return false and if it is in the string return true.

i tried to get this for a while and kept getting errors. my work is at school and its due tommarrow. if any of you could help me out i would really appreciate it.


09-07-01, 04:14 PM
i got most of it now...

ill post what i have a little later, i gg now


09-07-01, 07:39 PM
Use the find method in the string class.

#include <string>

bool isAValid (string &, string &);
bool isAValid (string & letter, string & stringToSearch){

if( stringToSearch.find(letter) == string::npos )
return false;
return true;

} // End isAValid()

Be sure to cast to a string when passing a char. A quick example of use:

int main(int argc, char *argv[]){

if( isAValid( string("a"), string("this is not true") ) )
cout << "true" << endl;
cout << "false" << endl;

return 0;

} // End main()