How to output new line in Visual Studio actions?

流过昼夜 提交于 2020-06-25 10:30:56

问题


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?


回答1:


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:

    (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;.




回答2:


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



来源:https://stackoverflow.com/questions/43464123/how-to-output-new-line-in-visual-studio-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!