Reputation: 63
We can change value manually by changing in variable tooltip or local/auto/watch window. But I want to change value of variable automatically to some specific hardcoded value or based on a code snippet. For eg.-
int main()
{
int a=0,b=1,c=2;
//bla bla
for(int i=0; i<100; ++i)
{
executeMe();
}
//bla bla
}
I want to put a breakpoint on line "executeMe()" and change value of 'b' to hardcoded value 3 or based on variable value 'c', so executing instruction 'b=c'. And continues execution without stopping everytime on breakpoint. How to do this in VS?
Upvotes: 0
Views: 104
Reputation: 63
Use the 'Print a message:' option instead of a macro. Values from code can be printed by placing them inside {}. The key is that VS will also evaluate the content as an expression - so {variable_name=0} should achieve the same as the macro example.
Thanks to Tom McKeown for this solution on stackoverflow.com/a/15415763/2328412
Upvotes: 1
Reputation: 3776
You could use #if preprocessor directives, which is similar with below code.
int a = 0, b = 1, c = 2;
for (int i = 0; i < 100; ++i)
{
#if DEBUG
b=3;
#endif
executeMe();
}
Upvotes: 0