【问题标题】:View the content of C++ smart pointer array in Visual Studio debugger?在 Visual Studio 调试器中查看 C++ 智能指针数组的内容?
【发布时间】:2016-12-16 04:36:27
【问题描述】:

对于 C++ 中指向数组的原始指针,前 N 个元素的内容可以通过将表达式复制到 Visual Studio 的 Watch 窗口中并在后面附加一个逗号来查看您想查看的元素(例如:testArray, 10)。当使用智能指针创建数组时,如何在 Watch 窗口中看到相同的内存内容?例如,如果通过以下语句创建了 unique_ptr:

unique_ptr<int[]> testArray = make_unique<int[]>(100)

我们如何查看缓冲区中的前 10 个元素?

【问题讨论】:

    标签: c++ arrays visual-studio smart-pointers unique-ptr


    【解决方案1】:

    试试这款手表:testArray._Mypair._Myval2, 10

    【讨论】:

    • 这取决于实现细节。这是一个教科书示例,说明该做什么,抱歉;)
    • @AsteroidsWithWings,是的,但这有效,而 x.get(),10 无效。 test.get(),10 Function std::unique_ptr&lt;__int64 [0],std::default_delete&lt;__int64 [0]&gt; &gt;::get has no address, possibly due to compiler optimizations.
    【解决方案2】:

    应该使用智能指针的get()方法:testArray.get() , 10

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 2019-07-09
      • 1970-01-01
      • 2010-11-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多