0

I've been trying to print to the debug console and the code that I've found for printing string doesn't work. The following lines are what I have been using to print to the debug. But I received the following error on the OutputDebugString(newPos.c_str());

line: argument of type "const char *" is incompatible with parameter of type "LPCWSTR".

I've also placed below the position and player position structs that I've used in the code and that are created earlier in the code.

struct Position {
    int x;
    int y;
    string currentObj;
};

struct PlayerPosition {
    int x;
    int y;
};

string newPos = gameMap[playerPos.x + 1][playerPos.y].currentObj;
OutputDebugString(newPos.c_str());

I've tried to go through some previous StackOverflow questions like this one and this other StackOverflow form here, but they haven't helped.

MatthewMartin
  • 32,326
  • 33
  • 105
  • 164

1 Answers1

2

It looks like OutputDebugStringW function is selected as OutputDebugString in your environment.

A simple fix is using OutputDebugStringA function explicitly instead of OutputDebugString:

OutputDebugStringA(newPos.c_str());
MikeCAT
  • 73,922
  • 11
  • 45
  • 70
  • Thanks, that seemed to fix the problem. Though if possible, I would like to ask another question; when I run the code and check the output from debug section, the only text that appears is that the c++ code was loaded correctly. Meanwhile, the code around the debug is still working, but I'm not receiving any debug messages. I assume this is an environment problem similar to the different OutputDebugString. – Montain Production Mar 04 '23 at 17:04
  • @MontainProduction Messages from `OutputDebugString` only appear in the Debug Console not the terminal or standard output. So the program needs to be run with a debugger attached and the Debug Console visible in the debugger. If nothing is visible try a hardcoded literal string as a test. – Richard Critten Mar 04 '23 at 17:22