5
|
1 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
|
2 |
<html lang="en">
|
|
3 |
|
|
4 |
<head>
|
|
5 |
<meta http-equiv="Content-Language" content="en-us">
|
|
6 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
|
7 |
<title>Creating your C++ file</title>
|
|
8 |
<link rel="stylesheet" type="text/css" href="../help.css">
|
|
9 |
</head>
|
|
10 |
|
|
11 |
<body>
|
|
12 |
|
|
13 |
<h1>Creating your C++ file</h1>
|
|
14 |
|
|
15 |
<p>You can begin coding your HelloWorld program. The .cpp file that you
|
|
16 |
create will be saved in the project folder you just created
|
|
17 |
<a href="cdt_w_newproj.htm">Creating a Makefile project</a>.</p>
|
|
18 |
|
|
19 |
<p>Files are edited in the C/C++ editor located to the right of
|
|
20 |
the C/C++ Projects view. The left margin of the C/C++ editor, called the marker
|
|
21 |
bar, displays icons for items such as bookmarks, breakpoints, and compiler errors and warnings.</p>
|
|
22 |
|
|
23 |
<p>For more information about:</p>
|
|
24 |
<ul>
|
|
25 |
|
|
26 |
<li>The editor area and marker bar, see <b>Workbench User Guide > Reference > User interface
|
|
27 |
information > Views and editors > Editor area</b></li>
|
|
28 |
<li>The marker bar icons, see <b>Workbench User Guide > Reference > User interface
|
|
29 |
information > Icons and buttons > Editor area marker bar</b></li>
|
|
30 |
</ul>
|
|
31 |
<p>To create a C++ file:</p>
|
|
32 |
<ol>
|
|
33 |
<li>In the <b>Project Explorer</b> view, right-click the <b>HelloWorld</b> project
|
|
34 |
folder, and select <b>New > Source File</b>.</li>
|
|
35 |
<li>In the <b>Source file: </b> field, type <b>main.cpp</b>.
|
|
36 |
<br>By default the source folder should be your project folder.
|
|
37 |
<br>The template selected is probably "Default C/C++ Source Template."
|
|
38 |
</li>
|
|
39 |
<li>Click <b>Finish</b>.</li>
|
|
40 |
<li>A Comment template probably appears at the top of an otherwise empty file.
|
|
41 |
Type the code, exactly as it appears below, in the editor.
|
|
42 |
Or you can paste it in from this help file.
|
|
43 |
</li>
|
|
44 |
<pre>
|
|
45 |
#include <iostream>
|
|
46 |
using namespace std;
|
|
47 |
|
|
48 |
int main () {
|
|
49 |
// Say Hello five times
|
|
50 |
for (int index = 0; index < 5; ++index)
|
|
51 |
cout << "HelloWorld!" << endl;
|
|
52 |
char input = 'i';
|
|
53 |
cout << "To exit, press 'm'" << endl;
|
|
54 |
while(input != 'm') {
|
|
55 |
cin >> input;
|
|
56 |
cout << "You just entered " << input
|
|
57 |
<< " you need to enter m to exit." << endl;
|
|
58 |
}
|
|
59 |
exit(0);
|
|
60 |
}
|
|
61 |
</pre>
|
|
62 |
|
|
63 |
|
|
64 |
<li>Click <b>File >
|
|
65 |
Save</b>.</li>
|
|
66 |
</ol>
|
|
67 |
|
|
68 |
<p>Your new .cpp file is displayed in the <b>Project Explorer</b> view. Your project now contains main.cpp. Before you
|
|
69 |
can build your HelloWorld project, you must create a makefile.</p>
|
|
70 |
|
|
71 |
<p>
|
|
72 |
<a href="cdt_w_newmake.htm" style="text-decoration: none">
|
|
73 |
<img border="0" src="../images/ngnext.gif" width="16" height="16" alt="Next icon"></a> <b><a href="cdt_w_newmake.htm">Next: Creating your makefile </a> </b>
|
|
74 |
</p>
|
|
75 |
|
|
76 |
<p align="left"><a href="cdt_w_newproj.htm" style="text-decoration: none">
|
|
77 |
<img border="0" src="../images/ngback.gif" width="16" height="16" alt="Back icon"></a> <b><a href="cdt_w_newproj.htm">Back: Creating your project</a></b></p>
|
|
78 |
|
|
79 |
<p><img border="0" src="../images/ngconcepts.gif" ALT="Related concepts" width="143" height="21">
|
|
80 |
<br>
|
|
81 |
<a href="../concepts/cdt_c_projects.htm">CDT projects</a><br>
|
|
82 |
<a href="../concepts/cdt_c_proj_file_views.htm">Project file views</a><br>
|
|
83 |
<a href="../concepts/cdt_o_code_entry.htm">Coding aids</a></p>
|
|
84 |
<p><img border="0" src="../images/ngtasks.gif" ALT="Related tasks" width="143" height="21">
|
|
85 |
<br>
|
|
86 |
<a href="../tasks/cdt_o_proj_files.htm">Working with C/C++ project files</a><br>
|
|
87 |
<a href="../tasks/cdt_o_write_code.htm">Writing code</a></p>
|
|
88 |
<p><img border="0" src="../images/ngref.gif" ALT="Related reference" width="143" height="21">
|
|
89 |
<br>
|
|
90 |
<a href="../reference/cdt_o_proj_prop_pages.htm">C/C++ Projects view</a></p>
|
|
91 |
|
|
92 |
<p>
|
|
93 |
<img src="../images/ng00_04a.gif" ALT="IBM Copyright Statement" >
|
|
94 |
</body>
|
|
95 |
|
|
96 |
</html> |