Sunday, 18 January 2015

ostringstream is the perfect C++ replacement for sprintf, except...

ostringstream is the perfect C++ replacement for sprintf, except for trying to debug its contents in Visual Studio.
Add this to Microsoft Visual Studio 12.0\Common7\Packages\Debugger\Visualizers\stl.natvis:

<Type Name="std::basic_ostringstream&lt;char,*&gt;">
<DisplayString>{_Mystrbuf->_Gfirst},s</DisplayString>
<StringView>_Mystrbuf->_Gfirst,s</StringView>
<Expand>
<Item Name="[state]">_Mystate</Item>
<ExpandedItem>_Mystrbuf->_Gfirst</ExpandedItem>
</Expand>
</Type>