So i have an array (size 5) of characters, each index containing a character, and i'm getting user input of a character to search for in the array. But i'm not sure how to check if char cInput
is present in all indexes of the array.
char cLetters[5] = {'b', 'b', 'b', 'b', 'b'};
char cInput;
cout << "Enter a character to search for: ";
cin >> cInput;
I shouldn't have to do this right?
if(cInput == cLetters[0] && cInput == cLetters[1] && cInput == cLetters[2]
&& cInput == cLetters[3] && cInput == cLetters[4])
return true;
Especially if the size of the array was 200, i wouldn't write that condition 200 times.
Any ideas?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…