blob: ec9251498b353f934f7ce17ccb076ab42cf18f38 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html lang="en">
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<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>
<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 your 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 marker bar, see <b>Workbench User Guide &gt; Reference &gt; User interface
information &gt; Icons and buttons &gt; Editor area marker bar</b></li>
<li>The editor area, see <b>Workbench User Guide &gt; Reference &gt; User interface
information &gt; Views and editors &gt; Editor area</b></li>
</ul>
<p>To create your C++ file:</p>
<ol>
<li>In the <b>C++ Projects</b> view, right-click the <b>HelloWorld</b> project
folder, and select <b>New &gt; File</b>.</li>
<li>In the <b>File name</b> box, type <b>main.cpp</b>.</li>
<li>Click <b>Finish</b>.</li>
<li>Type the code below in the editor. Lines are indented with tab
characters, not with spaces.</li>
<blockquote>
<p>#include &lt;iostream&gt;<br>
using namespace std;<br>
<br>
int main () {<br>
&nbsp;&nbsp;&nbsp;
// Say Hello five times<br>
&nbsp;&nbsp;&nbsp;
for (int index = 0; index &lt; 5; ++index) <br>
&nbsp;&nbsp;&nbsp;
cout &lt;&lt; &quot;HelloWorld!&quot; &lt;&lt; endl;<br>
<br>
&nbsp;&nbsp;&nbsp;
char input = 'i';<br>
<br>
&nbsp;&nbsp;&nbsp;
cout &lt;&lt; &quot;To exit, press 'm'&quot; &lt;&lt; endl;<br>
<br>
&nbsp;&nbsp;&nbsp;
while(input != 'm') {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
cin&nbsp; &gt;&gt; input;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
cout &lt;&lt; &quot;You just entered &quot; &lt;&lt; input <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;&lt; &quot; you need to enter m to exit.&quot; &lt;&lt; endl;<br>
&nbsp;&nbsp;&nbsp;
}<br>
<br>
&nbsp;&nbsp;&nbsp;
exit(0);<br>
}</p>
</blockquote>
<li>Click <b>File &gt;
Save</b>.</li>
</ol>
<p>Your new .cpp file is displayed in the C/C++ Projects
view and in the Navigator view. Your project now contains main.cpp. Before you
can build your HelloWorld project, you must next create a makefile.</p>
<p>
<a href="cdt_w_newmake.htm" style="text-decoration: none">
<img border="0" src="../images/ngnext.gif" width="16" height="16"></a> <b><a href="cdt_w_newmake.htm">Next: Creating your makefile </a> </b>
</p>
<p align="left"><a href="cdt_w_newproj.htm" style="text-decoration: none">
<img border="0" src="../images/ngback.gif" width="16" height="16"></a> <b><a href="cdt_w_newproj.htm">Back: Creating your project</a></b></p>
<p><img border="0" 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 border="0" 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 border="0" 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/ng03_04.gif" ALT="IBM Copyright Statement" BORDER=0 width="324" height="14">
</body>
</html>