0

What is WATCH in C++?

I have seen a lot of WATCH(someVariable) within a C++ code. Does anyone have an idea about what it is?

24th Feb 2017, 2:03 AM
Kleber Leal
Kleber Leal - avatar
4 Answers
+ 2
for using watch first you have to get into debugging moe.For that begin by using the ā€œStep intoā€ command. In Visual Studio 2005 Express, go to the debug menu and choose ā€œStep Intoā€, or press F11. If you are using a different IDE, find the ā€œStep Intoā€ command in the menus and select it. When you do this, two things should happen. First, because our application is a console program, a console output window should open. It will be empty because we havenā€™t output anything yet. Second, you should see some kind of marker appear to the left of the opening brace of main. In Visual Studio 2005 Express, this marker is a yellow arrow. If you are using a different IDE, you should see something that serves the same purpose.
24th Feb 2017, 3:14 AM
gaurav kulkarni
gaurav kulkarni - avatar
+ 2
This arrow marker indicates that the line being pointed to will be executed next.
24th Feb 2017, 3:18 AM
gaurav kulkarni
gaurav kulkarni - avatar
+ 2
Watching a variableĀ is the process of inspecting the value of a variable while the program is executing in debug mode. Most debuggers provide several ways to do this. Letā€™s take a look at a sample program: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 #include "stdafx.h" #include <iostream> int main() { Ā Ā Ā Ā int x =1; Ā Ā Ā Ā std::cout << x << " "; Ā  Ā Ā Ā Ā x = x + 1; Ā Ā Ā Ā std::cout << x << " "; Ā  Ā Ā Ā Ā x = x + 2; Ā Ā Ā Ā std::cout << x << " "; Ā  Ā Ā Ā Ā x = x + 4; Ā Ā Ā Ā std::cout << x << " "; Ā  Ā Ā Ā Ā return 0; } This is a pretty straightforward sample program -- it prints the numbers 1, 2, 4, and 8. First, use the ā€œRun to cursorā€ command to debug to the firstĀ std::cout << x << " ";Ā line: ļæ¼ At this point, the variable x has already been created and initialized with the value 1, so when we examine the value of x, we should expect to see the value 1. The easiest way to examine the value of a simple variable like x is to hover your mouse over the variable x. Most modern debuggers support this method of inspecting simple variables, and it is the most straightforward way to do so. ļæ¼ Note that you can hover over any variable x, not just the one on the current line: ļæ¼ If youā€™re using Visual Studio, you can also use QuickWatch. Highlight the variable name x with your mouse, and then choose ā€œQuickWatchā€ from the right-click menu. ļæ¼ This will pull up a subwindow containing the current value of the variable: ļæ¼ Go ahead and close QuickWatch if you opened it. Now letā€™s watch this variable change as we step through the program. First, choose ā€œStep overā€ twice, so the next line to be executed is the secondĀ std::cout << x << " ";Ā line: ļæ¼ The variable x should now have value 2. Inspect it and make sure that it does!
24th Feb 2017, 3:33 AM
gaurav kulkarni
gaurav kulkarni - avatar
+ 1
it was so big explanation so copied last part from google.hope you understood it.
24th Feb 2017, 3:34 AM
gaurav kulkarni
gaurav kulkarni - avatar