Thinks char I declared is const char *

Sorry for the second post in a short amount of time, but for some reason, I'm getting this error: invalid conversion from 'const char*' to 'char' [-fpermissive]. I've looked into this problem and couldn't find any suitable solutions. This is probably a stupid question, but I'm just a beginner. Thanks in advance!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
  void UpdateTxt(char input)
  {/*code*/}

//in int main
  if(kbhit())
        {
            char keyHit = getch();

            UpdateTxt(keyHit);
        }
        else if(GetAsyncKeyState(VK_SPACE))
        {
            char space = " ";//error on this line

            UpdateTxt(space);
        }
        else if(GetAsyncKeyState(VK_ACCEPT))
        {
            char enter = "\n";//and this line

            UpdateTxt("\n");
        }
enter and space are variables of type char. You cannot assign a string literal to a single char.

If a char is what you want, change the lines to resemble: char space = ' ';

Of course, you might not want to use those variables at all since they're superfluous.

UpdateTxt(' '); is more straightforward.
Last edited on
// obsolete post
Last edited on
The double quotes are used only for char* or char arrays or std::string, single quotes are for a single char.
For example:
1
2
3
4
char singleChar = 'A';
char *charPointer = "Hello";
char charArray[] = "Array";
std::string msg = "Hello world"
Oh thanks, that makes sense. Glad to know that
Topic archived. No new replies allowed.