string checker, that is passed a string and a character, and checks if the character is
within the string. If it is, it returns an integer of the index it is at. If it is not, it returns ‐1.
how can i do this?
I think you need to put your code in a function like this:
1 2 3 4 5 6 7 8 9 10 11 12 13
int in_string(const string& input, char ch)
{
string::size_type idx = input.find(ch);
if( idx== string::npos)
{
return -1;
}
else
{
// int and string::size_type are different so we need to cast it
returnstatic_cast<int>(idx);
}
}
In main you get the input, call the function and print the result