| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> |
| <html lang="en"> |
| |
| <head> |
| <meta http-equiv="Content-Language" content="en-us"> |
| <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> |
| <title>Creating your C++ file</title> |
| <link rel="stylesheet" type="text/css" href="../help.css"> |
| </head> |
| |
| <body> |
| |
| <div role="main"><h1>Creating your C++ file</h1> |
| |
| <p>You can begin coding your HelloWorld program. The .cpp file that you |
| create will be saved in the project folder you just created |
| <a href="cdt_w_newproj.htm">Creating a Makefile project</a>.</p> |
| |
| <p>Files are edited in the C/C++ editor located to the right of |
| the C/C++ Projects view. The left margin of the C/C++ editor, called the marker |
| bar, displays icons for items such as bookmarks, breakpoints, and compiler errors and warnings.</p> |
| |
| <p>For more information about:</p> |
| <ul> |
| |
| <li>The editor area and marker bar, see <strong>Workbench User Guide > Reference > User interface |
| information > Views and editors > Editor area</strong></li> |
| <li>The marker bar icons, see <strong>Workbench User Guide > Reference > User interface |
| information > Icons and buttons > Editor area marker bar</strong></li> |
| </ul> |
| <p>To create a C++ file:</p> |
| <ol> |
| <li>In the <strong>Project Explorer</strong> view, right-click the <strong>HelloWorld</strong> project |
| folder, and select <strong>New > Source File</strong>.</li> |
| <li>In the <strong>Source file: </strong> field, type <strong>main.cpp</strong>. |
| <br>By default the source folder should be your project folder. |
| <br>The template selected is probably <q>Default C/C++ Source Template.</q> |
| </li> |
| <li>Click <strong>Finish</strong>.</li> |
| <li>A Comment template probably appears at the top of an otherwise empty file. |
| Type the code, exactly as it appears below, in the editor. |
| Or you can paste it in from this help file. |
| |
| <pre> |
| #include <iostream> |
| using namespace std; |
| |
| int main () { |
| // Say HelloWorld five times |
| for (int index = 0; index < 5; ++index) |
| cout << "HelloWorld!" << endl; |
| char input = 'i'; |
| cout << "To exit, press 'm' then the 'Enter' key." << endl; |
| cin >> input; |
| while(input != 'm') { |
| cout << "You just entered '" << input << "'. " |
| << "You need to enter 'm' to exit." << endl; |
| cin >> input; |
| } |
| cout << "Thank you. Exiting." << endl; |
| return 0; |
| } |
| </pre> |
| </li> |
| |
| <li>Click <strong>File > |
| Save</strong>.</li> |
| </ol> |
| |
| <p>Your new .cpp file is displayed in the <strong>Project Explorer</strong> view. Your project now contains main.cpp. Before you |
| can build your HelloWorld project, you must create a makefile.</p> |
| |
| <p> |
| <a href="cdt_w_newmake.htm" style="text-decoration: none"> |
| <img src="../images/ngnext.gif" width="16" height="16" alt="Next icon"></a> <strong><a href="cdt_w_newmake.htm">Next: Creating your makefile </a> </strong> |
| </p> |
| |
| <p><a href="cdt_w_newproj.htm" style="text-decoration: none"> |
| <img src="../images/ngback.gif" width="16" height="16" alt="Back icon"></a> <strong><a href="cdt_w_newproj.htm">Back: Creating your project</a></strong></p> |
| |
| <p><img src="../images/ngconcepts.gif" ALT="Related concepts" width="143" height="21"> |
| <br> |
| <a href="../concepts/cdt_c_projects.htm">CDT projects</a><br> |
| <a href="../concepts/cdt_c_proj_file_views.htm">Project file views</a><br> |
| <a href="../concepts/cdt_o_code_entry.htm">Coding aids</a></p> |
| <p><img src="../images/ngtasks.gif" ALT="Related tasks" width="143" height="21"> |
| <br> |
| <a href="../tasks/cdt_o_proj_files.htm">Working with C/C++ project files</a><br> |
| <a href="../tasks/cdt_o_write_code.htm">Writing code</a></p> |
| <p><img src="../images/ngref.gif" ALT="Related reference" width="143" height="21"> |
| <br> |
| <a href="../reference/cdt_o_proj_prop_pages.htm">C/C++ Projects view</a></p> |
| |
| <p> |
| <img src="../images/ng00_04a.gif" ALT="IBM Copyright Statement" > |
| </div></body> |
| |
| </html> |