1

How do I get std::pair<char *, char *> to display as a proper string segment in Visual Studio, rather than as two pointers to null-terminated strings?

user541686
  • 205,094
  • 128
  • 528
  • 886

1 Answers1

1

Create %UserProfile%\Documents\Visual Studio 2015\Visualizers\custom.natvis (replace 2015 with your version of Visual Studio, obviously) and then try something like the following:

<?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>

Result:

Screenshot

user541686
  • 205,094
  • 128
  • 528
  • 886