Netbeans - Editing C & C++
Netbeans - Editing C & C++
Netbeans - Editing C & C++
The following short tutorial takes you through some of the features for navigating and editing the source files in a
C or C++ project in NetBeans IDE 6.7.
- Requirements
- Creating the Sample Project
- Editing C and C++ Source Files
- Navigating C and C++ Source Files
- Next Steps
Requirements
To follow this tutorial, you need the following software and resources.
See the NetBeans IDE 6.7 Installation Instructions and Configuring the NetBeans IDE for C/C++/Fortran
for information about downloading and installing the required software.
Sample Projects
Just want to play with some projects? In the IDE, choose File > New Project, then open the Samples category, the
C/C++ subcategory, and the C/C++ subcategory. The IDE provides several sample C and C++ projects to help
you familiarize yourself with the IDE.
2. In the project wizard, expand the Samples category and select the C/C++ subcategory.
1 of 16
2. Click Editor in the top pane of the window.
4. Select the language for which you want to set formatting style from the language drop-down list.
5. Select the style you want to set from the Style drop-down list.
1. In the Quote_1 application project, open the Source Files folder, then double-click the cpu.cc file to
open it in the Source Editor.
2. Click the collapse icon (small box with minus sign) in the left margin to fold the code of one of the
methods.
3. Mouse over the {...} symbol to the right of the folded block to display the code in the block.
2 of 16
Using Semantic Highlighting
You can set an option so that when you click on a class, function, variable, or macro, all occurrences of that
class, function, variable, or macro in the current file are highlighted.
5. Click OK.
6. In the customer.cc file of the Quote_1 project, notice that the function names are highlighted in bold.
8. All of the occurrences of the Customer class in the file are highlighted with a yellow background.
3 of 16
9. In the customer.h file, notice that class fields are highlighted in bold.
4 of 16
Using Code Completion
The IDE has a dynamic C and C++ code completion feature that enables you to type one or more characters
and then see a list of possible classes, methods, variables, and so on that can be used to complete the
expression.
1. Open the quote.cc file in the Quote_1 project, and right-click in the left margin of the Source Editor
and choose Show Line Numbers.
2. On the first blank line of the quote.cc, type a capital C and press Ctrl-Space. The code completion box
displays a short list that includes the Customer class. You can expand the list by pressing Ctrl-Space
again.
5 of 16
3. Select the Customer class and press Enter.
4. Complete the new instance of the Customer class by typing " andrew;". On the next line, type the
letter a and press Ctrl-Space. The code completion box displays a list of choices starting with the letter
a, such as method arguments, class fields, and global names, that are accessible from the current
context.
6 of 16
5. Double-click the andrew option to accept it and type a period after it. You are automatically provided
with a list of the public methods and fields of the Customer class.
7 of 16
3. Type ife, followed by a space. ife expands to if () {} else {}.
4. Type fori followed by a space. fori expands to for (int i = 0; i < ; i++) {}.
1. In the Quote_1 project, place the cursor after the { on line 114 of the module.cc file and press Return
to go to a new line.
2. Type enum state { and press Return. The closing curly bracket and semi-colon are added
automatically and the cursor is placed on the line between the brackets.
4. On the line after the closing }; of the enumeration, type if (. The closing parenthesis is added
automatically and the cursor is placed between the parentheses.
5. Type v==null. Then type { and newline after the right parenthesis. The closing bracket is added
automatically.
2. Expand the Quote_1 node. All classes in the project are listed.
8 of 16
4. Double-click the name variable to open the customer.h header file.
3. To navigate to an element of the file, double-click the element in the Navigator window and the cursor
in the Editor window moves to that element.
9 of 16
Finding Class, Method, and Field Usages
You can use the Usages window to show you everywhere a class (structure), function, variable, macro, or file is
used in your project's source code.
1. In the customer.cc file, right-click the Customer class on line 44, and choose Find Usages.
3. The Usages window opens and displays all of the usages of the Customer class in the source files of the
project.
1. In the quote.cc file, right-click on the main function and choose Show Call Graph.
2. The Call Graph window opens and displays a tree view of all of the functions called from the main
function.
10 of 16
3. Expand the endl node to display the functions called by that function.
4. Click the second button on the left side of the window to focus on the endl function, then click the
bottom button to change the graph to a tree view of all of the functions that call the function.
Using Hyperlinks
Hyperlink navigation lets you jump from the invocation of a class, method, variable, or constant to its
declaration, and from its declaration to its definition.
1. In the cpu.cc file of the Quote_1 project, mouse over line 36 while pressing Ctrl. The
ComputeSupportMetricfunction is highlighted.
11 of 16
2. Click the hyperlink and the editor jumps to the definition of the function.
12 of 16
3. Mouse over the definition while pressing Ctrl, and click the hyperlink. The editor jumps to the
declaration of the function in the cpu.h header file.
13 of 16
4. Click the left arrow in the editor toolbar and the editor jumps back to the definition.
14 of 16
1. In the Quote_1 project, open the module.cc file in the Source Editor.
2. Right-click on the #include "module.h" line in the file and choose Navigate > View Includes
Hierarchy.
3. By default, the Hierarchy window displays a plain list of files that directly include the header file. Click
the right-most button at the bottom of the window to change the display to a tree view. Click the
second button from the right to change the display to all files that include or are included. Expand the
nodes in the tree view to see all of the source files that include the header file.
2. Right-click on the declaration of the Module class and choose Navigate > View Type Hierarchy.
3. The Hierarchy window displays all of the subtypes of the Module class.
15 of 16
Next Steps
See Debugging C/C++ Projects for a tutorial on using some of the features for debugging a C or C++ project
in NetBeans IDE 6.5.
IMG
16 of 16