1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00
cdt/doc/org.eclipse.cdt.doc.user/getting_started/cdt_w_newcpp.htm
2009-07-29 14:31:33 +00:00

96 lines
3.7 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<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>
<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 <b>Workbench User Guide &gt; Reference &gt; User interface
information &gt; Views and editors &gt; Editor area</b></li>
<li>The marker bar icons, see <b>Workbench User Guide &gt; Reference &gt; User interface
information &gt; Icons and buttons &gt; Editor area marker bar</b></li>
</ul>
<p>To create a C++ file:</p>
<ol>
<li>In the <b>Project Explorer</b> view, right-click the <b>HelloWorld</b> project
folder, and select <b>New &gt; Source File</b>.</li>
<li>In the <b>Source file: </b> field, type <b>main.cpp</b>.
<br>By default the source folder should be your project folder.
<br>The template selected is probably "Default C/C++ Source Template."
</li>
<li>Click <b>Finish</b>.</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.
</li>
<pre>
#include &lt;iostream&gt;
using namespace std;
int main () {
// Say Hello five times
for (int index = 0; index &lt; 5; ++index)
cout &lt;&lt; "HelloWorld!" &lt;&lt; endl;
char input = 'i';
cout &lt;&lt; "To exit, press 'm'" &lt;&lt; endl;
while(input != 'm') {
cin >> input;
cout &lt;&lt; "You just entered " &lt;&lt; input
&lt;&lt; " you need to enter m to exit." &lt;&lt; endl;
}
exit(0);
}
</pre>
<li>Click <b>File &gt;
Save</b>.</li>
</ol>
<p>Your new .cpp file is displayed in the <b>Project Explorer</b> 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 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>
</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" alt="Back icon"></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/ng00_04a.gif" ALT="IBM Copyright Statement" >
</body>
</html>