Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare variables in Visual Studios immediate window in C++?

Recently I discovered that it's possible to declare variables in the Visual Studio immediate window while debugging. This feature is really useful because if I want to experiment with the code in that context, I can create new variables without modifying the real code in the new window, and I can then explore them in the watch window.

This works great for a C# project I have been debugging, but now I'm trying to do the same thing for a basic C++ declaration in a different project. I break at my breakpoint, and type the following into the immediate window:

int myVariable;

This gives the error:

CXX0013: Error: missing operator

Are there any steps that I need to get this to work with a C++ project?

like image 648
Kirby Avatar asked Mar 26 '13 22:03

Kirby


People also ask

How do I display a variable value in immediate window?

To view the variable's value, simply type its name into the immediate window and press Enter. The value, "Hello world" will be displayed beneath the typed line, as in the image above. To access properties of a variable or value, use the member access operator (.) as you would within source code.

What is the right way to declare a variable in Visual C#?

To declare a variable, you assign a name to the variable and state its data type. If you fail to do so, the program will run into an error. Variables are usually declared in the general section of the code windows using the Dim statement.


1 Answers

You can accomplish the same functionality by adding the new variable to your code window (rather than immediate window) while stopped in the debugger.

Make sure you have Tools->Options->Debugging->Edit and Continue->Enable native Edit and Continue checked.

int myVariable=444;

Then add your code, Debug->Apply Code Changes, and it works. Optionally use Set Next Statement to move the execution point to a different line.

like image 94
GravityWell Avatar answered Oct 31 '22 05:10

GravityWell