Im trying to compare the character count of a string with the index elements of an array, but am having trouble. For example, if the userInput equals XX, the output should be:
XX is not in the array at position 0.
XX is in the array at position 1.
XX is not in the array at position 2.
arr[] = {"X", "XX", "XXX"};
string userInput;
cin >> userInput;
for (int i = 0; i < userInput.length(); i++)
{
if (userInput[i] == arr[i])
{
cout << userInput << " is in the array at position " << i << endl;
}
else
{
cout << userInput << " is not in the array at position " << i << endl;
Im recieving this error and am not sure how to fix it. Im fairly new to programming so any help would be great. Thank you.
Invalid operands to binary expression ('int' and 'string' (aka 'basic_string, allocator >'))