Question: How can I compare a single character from a string, and another string (which may or may not be greater than one character)

This program gives me almost 300 lines of random errors. The errors don't reference a specific line number either, just a lot of stuff about "char\* ", "", or "std::to\_string".

```
#include <iostream>
#include <string>

using std::cout;
using std::string;

int main() {
    string str = "MDCXIV";
    string test = "D";

    if (test == str[4]) {     // This line causes the problems
        cout << test << endl;
    }
    return 0;
}

```

Answer: 
`str[4]` is a `char` type, which will not compare with a `string`.

Compare apples with apples.

Use

```
test[0] == str[4]

```

instead.
I think you might be mixing python with c++. In c++ `'g'` refers to a single character `g` not a string of length 1. "g" refers to an array (string) which is 1 character long and looks like ['g']. So as you can see, if you compare a single character to an array of characters no matter if the array is a single character long, this operation is not defined.

This will work if define it yourself by building a class which is able to compare string of one character long to a single character. Or just overload the `==` operator for doing just that

Example:

```
#include <iostream>
#include <string>

using std::cout;
using std::string;
using std::endl;

bool operator == ( const string &lh, const char &rh) {
    if (lh.length() == 1) return lh[0] == rh;
    return 0;
}

int main() {
    string str = "MDCXIV";
    string test = "D";

    if (test == str[4]) {
        cout << test << endl;
    }
    else cout << "Not a match\n";
    return 0;
}

```