News: - Used by 85,000 Members - SMS Backed up 7,35,000 - Contacts Stored  28,850 !!

Main Menu

Creating a New C++ Source File

Started by sukishan, Aug 13, 2009, 12:49 PM

Previous topic - Next topic


Creating a New C++ Source File
In your project you will want to have at least one C++ source file containing the code for your program. If you have just created a new project, that project will probably already be active. Select Project, Set Active Project to see what project is currently the active one. If it is not the one to which you want to add your C++ source file, click on the correct one.

Once you are sure that you have the correct project active, select File, New. Click on the Files tab and click on C++ Source File. Then fill in the desired file name. The .cpp extension will be added automatically; there is no need to type that.

The project name and location should be correct, but glance at them to be sure. The Add to Project box should be checked and the correct project name should be shown below it. See this picture of these choices to have a better idea of what this looks like. Finally, click on OK.

You should then be in the editor, editing a blank .cpp document with the correct name. Type in your desired code. Select File, Save to save your file. You can also copy in code from another file by selecting Insert, File as Text. It is also possible to add code to a new file by using Cut, Copy, and Paste (found under Edit) to bring in code from another file.

Sometimes you will want to use more than one C++ source file. It is typical to place the main function in one source file, other stand-alone functions in another source file, and functions belonging to a user-defined class in their own source file. All of these files that belong to the same program must be added to the same project.

Hint: Make sure that all of your project's .cpp and .h files (and any data files as well) are all located under your project directory. You can use My Computer to check on the locations of these files. Many students run into problems with their projects because they have several versions of their files in various directories and don't know which ones are being used by their project.
A good beginning makes a good ending

Quick Reply

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it has been approved by a moderator.

Please leave this box empty:
Type the letters shown in the picture
Listen to the letters / Request another image

Type the letters shown in the picture:

Shortcuts: ALT+S post or ALT+P preview