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: 
You need to convert str[4] (which is a char) to a string before you can compare it to another string. Here's a simple way to do this

```
if (test == string(1, str[4])) {

```
Also you need `"D"` to be a char value not a string value if you are comparing it like that. 

```
std::string myString = "Hello World";
const char *myStringChars = myString.c_str();

```

You have to turn it into a char array before can access it. Unless you do.

```
str.at(i);

```

which you can also write as

`str[i]` <-- what you did.

Essentially, this all boils down to test needs to initialized like `char test = 'D';` 

Final Output..

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

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

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

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

```