如何在Visual Studio操作中输出换行? [英] How to output new line in Visual Studio actions?

查看:917
本文介绍了如何在Visual Studio操作中输出换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2015中添加了一个断点,并带有将字符串输出到 Output Window 的操作.最后将有一个自动添加的换行符.问题是,我以前的输出消息(不是按断点输出的)没有换行符.

因此,我想在字符串的开头添加新的行字符,以避免它与我之前的消息混淆.我尝试添加\n,但是\n照原样输出,没有被转义.

如何在断点动作中添加换行符?

解决方案

以下是您可以尝试的四件事:

  1. 您可以使用调试器表达式{"\n",s8b} 产生换行符,该表达式使用的示例:

    (除此之外,我不知道在消息中包含换行符的任何其他方法.虽然有 种输入多行消息的方法(通过输入换行符的Unicode使用小键盘的代码点),Visual Studio只会丢弃除输入的第一个文本行以外的所有内容.)

  2. 在当前断点之前,添加带有非常简短的操作消息的附加断点(点或逗号),以便在实际消息之前获得额外的换行符.

  3. p>
  4. 如果您使用的是Windows(对于Visual Studio,这似乎很可能),则可以使用Windows API函数如何在Win32应用程序中打印到调试输出窗口?"

  5. 写一条消息到clog :std::clog << message << std::endl;.

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?

解决方案

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

这篇关于如何在Visual Studio操作中输出换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆