Document directory
- 1. Set program breakpoint
- 2. Run the program
- 3. One-step execution Program
- 4. Set the watch window
- 1. Full indent
- 2. Description of the inserted Program
The following articles are copied to facilitate viewing.
This article was accidentally discovered on the Internet. I wrote it a long time ago. DEV C ++ has already developed a new version, but this article is sufficient for most people. The advantage of using dev c ++ is that it integrates with gnu gcc and has better compatibility with ansi c/C ++ than Microsoft's VS series. I believe that participation in ACM and other students who need to process code using GCC is a good choice. The original text is as follows::
Dev-C ++ is a visual integrated development environment that can be used to edit, pre-process, compile/link, run, and debug C/C ++ programs. This manual describes some common basic operations of Dev-C ++.
1. Start Dev-C ++
Method 1:
1. click the "Start" button in the taskbar, select the "program" menu item, and select the "Bloodshed Dev-C ++" sub-menu item under "program, displays the sub-menu under this item.
2. Click the "Dev-C ++" menu to start the Integrated Development Tool Dev-C ++. (1)
Figure 1
Method 2:
Click the Dev-C ++ icon on the desktop.
2. Create a source program
1. select "File"> "New"> "Source File" ("File"> "New"> "Source code") from the main menu, as shown in figure 2 ).
Figure 2
If you can see that the word on the interface is Chinese, you can change the interface to English according to the following operations. Click "Tools"> "Environment options" in the main menu, select the interface page in the pop-up dialog box, and select Chinese from the Language drop-down list, as shown in. In this case, all menus and toolbar names on the interface are named in English.
2. A white area appears in the lower right of the screen. Enter the program here. See figure 3.
Output Tab
Source code editing area
Toolbar
Menu
Figure 3
3.Save source program to Hard Disk
A good habit is that after a new program is created, the program is saved to a directory on the hard disk before the code is entered, and the program is frequently saved during the editing process, to prevent sudden power outages or crashes. To Save the program, you only need to select "File"> "Save" from the main menu to Save the File to the specified hard disk directory. 4.
Figure 4
A dialog box is displayed, as shown in Figure 5. Here you need to specify the directory where the file is to be stored (F: \ temp here), the file name (test here), and the storage type. Note that C source files (*. c) must be selected for the storage type, which means that the storage location is a C file. After you click the Save button in the lower-right corner, a source file named test. c is displayed in the temp directory.
Figure 5
4.Edit the program in the program editing area, 6. Remember to Save the program at any time when entering the program (use the menu "File"-> "Save", or press Ctrl + s ), at this time, the program will be resaved to the previously specified directory, such as F: \ temp. If you want to Save the program to another hard drive path, you can select "File"-> "Save ...", 7. You can specify the program name and save path again.
Figure 6
Figure 7
Note:
1.EnglishEdit the program in the input environment (if you can enter Chinese in the editing area, it means you are in the Chinese Input environment. To input a program, you must switch to the English input environment ).
2.In the Dev-C ++ environment, to view the program running result, you must add system ("PAUSE") or system ("pause") before the return Statement of the main function "); in this way, when the program runs the Statement, the result display screen will stay, so that everyone has time to view the output results of the program. Otherwise, the screen will flash.
3. preprocessing, compilation, and linking programs
Select "run"> "compile" from the main menu (you can also compile the current file) or press the shortcut key "Ctrl + F9" to complete the preprocessing, compilation, and link processes of the program at one time. If the program contains lexical, syntax, and other errors, the compilation process fails. The Compiler displays the error information in the "Compile Log" tab in the lower-right corner of the screen, as shown in figure 8, and mark the corresponding error line of the source program as a red base color, as shown in Figure 9 (because the semicolon after the printf statement is deleted, an error is reported during compilation, A syntax error occurs in the statement before the system statement )).
Figure 8
Figure 9
The error information displayed on the "Compile Log" tab is an important source for finding the cause of the error,Every student must learn to read these error messages.And every time you encounter an error and finally solve the errorRecord error information and Corresponding Solutions. In this way, the system will see similar error messages and be able to skillfully reflect the problem of the source program, thus improving the program debugging efficiency.
After the lexical and syntax errors in the program are excluded, the compilation is successful. The. exeexecutable file (such as test.exe) with the same name will appear in the source file catalog ). Double-click the file to run the program.
4. Run the program
After preprocessing, compiling, and linking a program, you can run the program in two ways. 2. Directly select "Excute"-> "Run" from the main menu in the Dev-C ++ environment or press the shortcut key "Ctrl + F10" to Run the program. 10.
Figure 10
5. debug the program
The program through preprocessing, compilation, and linking only has no lexical or syntax errors in the program, and cannot discover deep-seated program problems (for example, incorrect algorithms lead to incorrect results ). When the program is running incorrectly, you need to find out the cause of the error. Reading the program carefully to find errors is certainly a method, but sometimes the problem cannot be solved by simply reading the program,In this case, program debugging (Debug) Means. This is an effective troubleshooting method that everyone needs to master.
1. Set program breakpoint
The basic idea of debugging is to let the program run before the code that you think may have errors, then stop and run the statements one by one under the control of a person, you can view the values of related variables during running to determine the cause of the error. If you want to pause the program to a row, you need to set the row to a breakpoint.You can click, This row will be highlighted. The highlighted color is red by default. 9. If the system ("pause") statement is set to a breakpoint, the program stops running the printf statement. It should be noted that you can set multiple breakpoints in the program as needed.
If you want to cancel a line of code from being a breakpoint, click it at the beginning of the line.
Figure 9
2. Run the program
After the breakpoint is set, the program runs into the debug state. To Run a program, you cannot use the main menu "Execute"-> "Run", but use the main menu "Debug"-> "Debug" (or press the shortcut key F8), as shown in 10.
Figure 10
The program will run at the first breakpoint, And the highlighted color at the breakpoint will change from red to blue, indicating that the next code will run the blue background, as shown in 11.
Figure 11
Note: Sometimes you will find that even if you set a breakpoint and click "Debug"-> "Debug" on the main menu, the program will not stay at the breakpoint. Solution: cancel the breakpoint, re-compile the program, set the breakpoint, and click "Debug"> "Debug" on the main menu.
3. One-step execution Program
To run the blue background code, use "Next Step (F7)" shown in figure 10 )","Step Into (Shift F7)", "Continue (Ctrl F7)", "Run to Cursor (Shift F4)", and so on (for specific meanings, see the introduction below ). Before learning a function, we generally use Next Step and Continue. Step Into is also used after learning the function.
Debug menu 12. The menu items related to a single-step operation are described as follows: Next Step(F7): Run the next line of code. If the next line calls a function, it does not enter the function body. Step(Shift F7): Run the next line of code. If the next line calls a function, it enters the function body; Continue(Ctrl F7): Run to the next breakpoint; Run to Cursor (Shift F4): Run to the output of the cursor; |
Figure 12
4. Set the watch window
When debugging a program, you may need to check the value of the variable during the program running to check whether the program processes the variable correctly. You can Add Watch in the debugging menu) window to add the variable watch. The new variables will be displayed on the Debug page on the leftmost release E, as shown in 13. If the current page in release E on the left is not a Debug page, you can click the Debug tab to make it the current page.
Figure 13
6. Open an existing Program
Click "File"-> "Open Project or File" in the main menu, as shown in figure 14. In the displayed dialog box, specify the File path and select the File to Open.
Figure 14
7. Some operations to improve the writing style of the program 1. Full-range indent
Using appropriate indentation can improve code readability. Select the code segment to be indented, and click "Edit"-> "Indent" under the main menu. As shown in 15, the entire code segment can be shifted to N characters.
Figure 15
You can customize the number of characters to be moved for each indent as follows: ClickIn the "Tools"-> "Edit Options" section of the main menu, set the "General" Tab in the pop-up dialog box and set the "Tab Size" to the expected number. We recommend that you set it to 3 or 16. This dialog box provides a custom Dev-C ++ interface editing style function. If you are interested, you can study it yourself.
You can also click "Edit"-> "Unindent" to move the entire code segment to the left.
Figure 16
2. Description of the inserted Program
It is a good habit to briefly describe the functions of the program in the source program. You can click "Edit"-> "Insert"-> "Comment Header", 16, insert a comment at the cursor in the program editing area, as shown in figure 17.
The insert effect is shown in Figure 18.
Figure 17
Figure 18