2

I'm trying to add a simple diagnostic output to a C++ UWP shared project akin to System.Diagnostics.Debug.WriteLine in C#. Following the documentation for OutputDebugString here and this solution here I've tried this:

char buf[1024]; sprintf(buf, "frequency = %f", (float)result); OutputDebugString(buf); 

but I get the compiler error

argument of type "char*" is incompatible with parameter of type "LPCWSTR"

How do I fix this?

2
  • Use OutputDebugStringA() if you want to display a char[]. Commented Nov 14, 2016 at 14:13
  • That worked - thanks Hans (N.B. I also needed to swap sprintf to sprintf_s). Commented Nov 14, 2016 at 14:30

2 Answers 2

3

A colleague advised me to add

#include "strsafe.h" 

after any pre-compiled headers and then use this code instead

TCHAR buf[1024]; size_t cbDest = 1024 * sizeof(TCHAR); StringCbPrintf(buf, cbDest, TEXT("frequency = %f"), (float)result); OutputDebugString(buf); 

I also needed to remember to swap the debugger to handle mixed code:

VS2015 screenshot

Sign up to request clarification or add additional context in comments.

1 Comment

msdn.microsoft.com/en-us/library/windows/desktop/… describes when TCHAR is char or wchar_t, etc
1

Here is what I use most of the time (notice the "L"):

#include <Windows.h> OutputDebugString(L"Sarah Connor ?\n"); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.