12

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?

Micha Wiedenmann
  • 19,979
  • 21
  • 92
  • 137
Kirby
  • 3,649
  • 3
  • 26
  • 28
  • 2
    Managed code is a tool builder's delight. This is not available in the C++ IDE. – Hans Passant Mar 26 '13 at 22:26
  • What are you trying to accomplish? The immediate window for C++ is extremely limited; I don't think you can declare a variable like that (or even what behavior you would expect). – Collin Dauphinee Mar 26 '13 at 22:26
  • [MSDN](http://social.msdn.microsoft.com/Forums/en-US/vsdebug/thread/c46d84af-5a77-4313-99d6-7cfbd16943a1) seems to say it's C# only - not even possible in VB. – Scott Mermelstein Mar 26 '13 at 22:27

1 Answers1

9

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.

GravityWell
  • 1,547
  • 1
  • 18
  • 22
  • When you say code window, do you mean the source code that I'm stopped the debugger in? Yeah, that I know, but by checking off _Enable native Edit and Continue_, is that it disables the _data viewing enhancements_ i.e. [data natural visualization](http://code.msdn.microsoft.com/Writing-type-visualizers-2eae77a2) which is not acceptable. :( Also, in some cases, e.g. debugging a .dll, this will not work esp if the .dll is in use elsewhere (I've run in to this problem) – Adrian Jul 04 '14 at 18:11