2

假设我有一个std::vector<Foo>size 30Foo结构定义为:

struct Foo {
    int a,b,c,d,e,f,g,h,i,j,k,l,m; //many fields
    // ...
};

是否可以仅“观察”g向量所有元素的字段内容?

我认为 Watch Window 中的表达式如下:

(v)._Myfirst[$index].g
//v would be the variable holding the vector being debugged

就足够了。

4

1 回答 1

1

如果您将可视化工具信息添加Foo到 %VSINSTALLDIR%\Common7\Packages\Debugger\autoexp.dat,您应该只需通过观看v.

例如,假设您v填充了 3 Foos,其g值为 111、222 和 333。如果将以下内容添加到 autoexp.dat 的末尾:

Foo {
    preview (
        $c.g
    )
}

观察窗口看起来像:

VS10 观察窗口


或者您可以添加:

Foo {
    preview (
        #("g = ", $c.g)
    )
}

产生:

VS10 观察窗口

于 2012-07-04T23:46:35.853 回答