1

如何std::pair<char *, char *>在 Visual Studio 中显示为正确的字符串段,而不是显示为指向空终止字符串的两个指针?

4

1 回答 1

1

创建%UserProfile%\Documents\Visual Studio 2015\Visualizers\custom.natvis(显然替换2015为您的 Visual Studio 版本),然后尝试以下操作:

<?xml version='1.0' encoding='utf-8'?>
<AutoVisualizer xmlns="http://schemas.microsoft.com/vstudio/debugger/natvis/2010">
  <!-- For more information on how to create debugger visualizers, refer to:
       https://msdn.microsoft.com/en-us/library/jj620914.aspx
       https://msdn.microsoft.com/en-us/library/75w45ekt.aspx
  -->
  <Type Name="std::pair&lt;*,*&gt;">
      <DisplayString Condition="*second - *first &gt;= 0">{first,[second - first]}</DisplayString>
  </Type>
  <Type Name="std::pair&lt;*,*&gt;">
      <DisplayString Condition="*second._Ptr - *first._Ptr &gt;= 0">{first._Ptr,[second._Ptr - first._Ptr]}</DisplayString>
  </Type>
</AutoVisualizer>

结果:

截屏

于 2018-03-21T21:42:25.343 回答