I'm new to C++, and since my first computer language is Python, I don't really understand what I did wrong here.
The purpose of this code is to find out how many certain alphabets are included in a string of length 8, but I keep getting the following error:
ISO C++ forbids comparison between pointer and integer [-fpermissive]
#include <iostream>
using namespace std;
int main() {
int cnt = 0;
string temp;
cin >> temp; // the input string will be of length 8
for (int i = 0; i < 8; i++) {
if (temp[i] == "F") {
cnt += 1;
};
};
cout << cnt << endl;
return 0;
}
When I print out temp[i]
in the code, I can confirm that temp[i]
is printed out as a single character, which I believe can be compared with another character, in this case the character "F"
.
I've been trying to find out why this is happening, but ended up coming here to ask for help.