Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com
Answertopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

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:

  1. In the Project Explorer view, right-click the HelloWorld project folder, and select New > Source File.
  2. In the Source file: field, type main.cpp.
    By default the source folder should be your project folder.
    The template selected is probably "Default C/C++ Source Template."
  3. Click Finish.
  4. 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.
  5. #include <iostream>
    using namespace std;
    
    int main () {
        // Say Hello five times
        for (int index = 0; index < 5; ++index)
          cout << "HelloWorld!" << endl;
        char input = 'i';
        cout << "To exit, press 'm'" << endl;
        while(input != 'm') {
            cin  >> input;
            cout << "You just entered " << input
                 << " you need to enter m to exit." << endl;
        }
        exit(0);
    }
    
  6. 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.

Next icon Next: Creating your makefile

Back icon Back: Creating your project

Related concepts
CDT projects
Project file views
Coding aids

Related tasks
Working with C/C++ project files
Writing code

Related reference
C/C++ Projects view

IBM Copyright Statement


 
 
  Published under the terms of the Eclipse Public License Version 1.0 ("EPL") Design by Interspire