Inspecting STL containers in Visual Studio debugging

前端 未结 10 1374
旧巷少年郎
旧巷少年郎 2020-12-05 06:52

If I have a std::vector or std::map variable, and I want to see the contents, it\'s a big pain to see the nth element while debugging. Is there a p

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-05 07:43

    Most simply method is you have to ready a pointer to watch variable like this.

    vector a = { 0,1,2,3,4,5 };
    int* ptr = &a[0]; // watch this ptr in VisualStudio Watch window like this "ptr,6".
    

    I tried "a._Myfirst[0]" in VisualStudio2015, But It wasn't display array data.

    If you can use "natvis", it will resolve your problems.

    This is "sample.natvis" for display std::vector data for Visual studio 2015.

     
    
      
        {{ size={_Mypair._Myval2._Mylast - _Mypair._Myval2._Myfirst} }}
        
          _Mypair._Myval2._Mylast - _Mypair._Myval2._Myfirst
          _Mypair._Myval2._Myend - _Mypair._Myval2._Myfirst
          
            _Mypair._Myval2._Mylast - _Mypair._Myval2._Myfirst
            _Mypair._Myval2._Myfirst
          
        
      
    
    

    Before

    After

提交回复
热议问题