operand types are incompatible ("char" and "const char *")
You should use the standard C++ string class. C-style strings are awkward, low level, and easy to get wrong (as evidenced by this thread). However, let's look at the problems in your original code, and ignore all of the wrong advice you've been given up to this point.
This is wrong:
char* arrayMap[5225];
...
mapReader >> arrayMap[i];
Why is it wrong? Because arrayMap[i]
doesn't point to memory that you own; you're extremely likely to get a memory access violation at runtime. Memory must be allocated first, but doing that would be awkward, low level, and easy to get wrong (as evidenced by this thread). Yes, I'm intentionally repeating myself.
This is wrong too:
if (arrayMap[i] == "X")
The equality operator doesn't work the way you think it does at a lower level. arrayMap[i]
is a pointer, and "X"
evaluates to a pointer. Unless the planets align and you get a perfect storm of shared string literals in the compiler implementation and arrayMap[i]
was conveniently initialized to "X"
, this test will always fail.
To compare C-style strings you must compare all characters up to a null character ('\0'). The simplest way to do that is by calling the std::strcmp() function:
if (std::strcmp(arrayMap[i], "X") == 0)
Or, since these are single character tests, you can just look at the first character:
if (arrayMap[i][0] == 'X')
But you can greatly simplify things by using …