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?
Asked
Active
Viewed 292 times
1

user541686
- 205,094
- 128
- 528
- 886
-
1Interesting how to modify how the MSVC debugger shows things, even though for C++17+ this specific data-type should be replaced by a `std::string_view`. – Deduplicator Mar 21 '18 at 22:33
-
@Deduplicator: Yeah, I knew someone was going to say that... – user541686 Mar 21 '18 at 22:34
-
Glad to be of service. – Deduplicator Mar 21 '18 at 22:35
1 Answers
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<*,*>">
<DisplayString Condition="*second - *first >= 0">{first,[second - first]}</DisplayString>
</Type>
<Type Name="std::pair<*,*>">
<DisplayString Condition="*second._Ptr - *first._Ptr >= 0">{first._Ptr,[second._Ptr - first._Ptr]}</DisplayString>
</Type>
</AutoVisualizer>
Result:

user541686
- 205,094
- 128
- 528
- 886