Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to output new line in Visual Studio actions?

I add a break point in Visual Studio 2015, with an action to output a string to Output Window. There will be an auto-added line break at the end. Problem is, my previous output message(which is not output by break point) has no line break.

So I want to add new line character at the beginning of my string, to avoid it messing up with my previous message. I tried to add \n, but the \n outputs as it is, without being escaped.

How to add a new line character in break point's action?

enter image description here

like image 679
zhm Avatar asked Apr 18 '17 05:04

zhm


2 Answers

Here are four things for you to try:

  1. You can produce a line break using the debugger expression {"\n",s8b} which makes use of the C++ debugger format specifier s8b (unquoted 8-bit string).

    Here's an example with a two-line message First{"\n",s8b}Second:

    Demonstration of line break in debugger tracepoint message

    (Other than that, I am not aware of any other way to include line breaks in the message. While there are ways to enter a multi-line message (by entering line break characters' Unicode code points using the numpad), Visual Studio will just throw away everything but the first text line entered.)

  2. Just before your current breakpoint, add an additional breakpoint with a very short action message (a dot or comma) in order to get an additional line break before your real message.

  3. If you're on Windows (which appears likely, given Visual Studio), you can send a message to the debugger using the Windows API function OutputDebugString. This is the currently suggested solution to the SO question, "How do I print to the debug output window in a Win32 app?"

  4. Write a message to clog: std::clog << message << std::endl;.

like image 122
stakx - no longer contributing Avatar answered Nov 07 '22 19:11

stakx - no longer contributing


In Addition to the answer from stakx that matches the original question for debugging C++ applications, I would like to add a character sequence that instead works for debugging .NET applications:

{"\n",nq}

The C++ sequence would otherwise result in this error message: 's8b' is not a valid format specifier

like image 31
CodeFox Avatar answered Nov 07 '22 18:11

CodeFox