Creating your C++ file
You can begin coding your HelloWorld program. The .cpp file that you create will be saved in the project folder you just created Creating a Makefile project.
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.
For more information about:
- The editor area and marker bar, see Workbench User Guide > Reference > User interface information > Views and editors > Editor area
- The marker bar icons, see Workbench User Guide > Reference > User interface information > Icons and buttons > Editor area marker bar
To create a C++ file:
- In the Project Explorer view, right-click the HelloWorld project folder, and select New > Source File.
- In the Source file: field, type main.cpp.
By default the source folder should be your project folder.
The template selected is probablyDefault C/C++ Source Template.
- Click Finish.
- 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.
#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; }
- Click File > Save.
Your new .cpp file is displayed in the Project Explorer view. Your project now contains main.cpp. Before you can build your HelloWorld project, you must create a makefile.
CDT projects
Project file views
Coding aids
Working with C/C++ project files
Writing code