简体   繁体   中英

visual studio breakpoints

I have a question about setting breakpoints in Visual Studio 2010 Professional.

In the struct below, I have an Update() function which, depending on certain conditions, updates the value of it's member i :

struct A
{
    A(int i) : i(i) {}

    void Update()
    {
        //Update i if some condition is met...
        if(something)
            i += 2;
    }

    int i;
};

int main()
{
    A a(2);

    //Update is usually called periodically...
    a.Update();

    return 0;
}

I would like to set a breakpoint to be hit when i equals 4. The only way I know how to do this is to change the Update() function like so:

void Update()
{
        //Update i if some condition is met...
        if(something)
            i += 2;

        if(i == 4)
            int dummy = 1;
}

Now I can set a breakpoint on the line:

int dummy = 1;

And I will hit a breakpoint when i equals 4 . Is there a cleaner or easier way to set a breakpoint in a situation like this? How do I do it without adding in the dummy code?

Set a breakpoint in the usual way with your mouse. This puts a big red dot in the left margin of your code. Now right-click on the big red dot with your mouse. You will see a list of ways you can change your breakpoint. Choose "Condition...". Then you can enter i==4 into the condition box. You'll have a breakpoint that breaks at that point when i is 4.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM