0

I'm making an rpg. When i enter the code(shown below) i get this error. What am i doing wrong?

main.cpp|15|error: invalid conversion from 'const char*' to 'char' [-fpermissive]|

#include <iostream>
#include <stdio.h>
#include <string>
#include <windows.h>

using namespace std;

int mainLoop()
{
    char arr[4] = {'x', 'x', 'x', 'x'};
    int pp = 1;
    bool end = false;
    string inp;

    arr[pp] = "S";

    while(end == false)
    {
        cout << arr << endl;
        cout << ">>: " << endl;
        cin >> inp;

        if(inp == "move")
        {
            pp++;
        }

    }
}

int main()
{
    mainLoop();

    return 0;
}

EDIT:

Thanks! but now i have it leaving the old pp(player position) as S. I have tried making a new variable ppold and making it change pp-1 to x but nothing happens.

2 Answers2

6
arr[pp] = "S";  //incorrect

should be

arr[pp] = 'S';  //correct

The type of "S" is char[2] which is not convertible to char which is the type of arr[pp]. But the type of 'S' is char which matches with the type of arr[pp] (which is char also).

Nawaz
  • 353,942
  • 115
  • 666
  • 851
2

"S" (double quotation mark) means it is a null terminated string, which is {'S', '\0'} when expanded.

'S' (single quotation mark) means it is a char character, which is {'S'} when expanded.

arr[X] is a character in a character array in your example (think of it as a single quotation expression, like 'a')

You cannot assign {'S', '\0'} to {'a'}.

Here is more information about the situation.

Community
  • 1
  • 1
Etherealone
  • 3,488
  • 2
  • 37
  • 56