In this video, we'll go over the steps necessary to create our own custom project template.
The idea here is that we can create our own project templates, and when we create our projects, we
can use this template as the starting point.
That way we'll have a proper main CPP file.
We'll have all our switches set.
We'll have our environment set.
All right, so let's get started.
First thing you need to do is open up a workspace.
I've got a workspace already open, already created, I should say.
I'm going to open it now.
I'm going to say open workspace.
If you don't have a workspace at all, you could just say file new workspace.
So I'll open the workspace that I've got.
It's on my desktop and it's called CP workspace.
So I'll open that.
And the first thing you want to do is you want to add a project.
So you want to right click on your workspace and say New, new project.
Now here you've got the new project Wizard and you've got different examples.
You can create gooey applications, console applications, you can have user templates and so forth.
What we want to do is we want to use the simple executable plus plus template that comes with code light,
and we want to tweak that our own way.
And then what we want to do is we want to create our own template and here that we can choose and we
could put it in console or we can put it here in user templates, we could put it wherever we'd like.
Okay.
But before we do that, we need to create a project.
So let's do that.
I'm going to select console and let's use the G plus plus simple executable console template press next.
The project name.
It doesn't really matter.
I'll just say sample since we're going to save it as a template anyway and I'll select next.
We want to make sure our compilers are set up correctly.
Here I'm using min gw and the GDB debugger select finish.
And that creates our project.
You can see here's the source file and here's the CP file, which is really C code and not C++ code.
But we'll fix all this in a minute.
So first thing we want to do is we want to get rid of this and let's write a simple C++ program, same
one we've been writing all along.
So we'll say include IO stream, we'll include IO streams since we're going to probably use it in most
of the projects that we write, then we have our main function.
And again it's int main open closed friends and then an open curly which will be automatically closed
by code.
Like here we can indent in by just pressing tab and we could say STD two colons see out and then the
insertion operator followed by the string hello world and you can type anything you like here for hello
world and we'll do also an STD two colons and del.
This prints a new line that way when we display hello world the cursor will go to the next line on the
console and then finally we'll just return zero like we always do.
That's it.
I'm going to save this so that press control is here.
So I've just done that and saved it.
Now we'll set some compiler settings.
We'll do this the one time, then we'll save it as a project template.
So let's go to the sample project, the actual project name, and we'll right click go down to settings.
Global settings and we want to make sure we've got those two compiler options set.
So we're going to right click on those three little dots here on the button.
You want to select that button and click, and we want to make sure that we've got our all warnings
enabled on and our C++ 14 standard on.
Press.
Okay.
Then you want to come to us as code completion and select that and select enable C++ 14 Standard Apply.
And that's it.
Now, what we can do is we can come to the project again, right click and say Save as template.
So I'll select that.
And what's the project name?
This could be anything we want.
We could just say frank template or template for course or any name you like rather than that.
I'm just going to say Frank, let's see G plus.
Plus.
Console.
Template.
I think it's pretty picky about spaces, so I'm just going to use those dashes and it is a console application.
If you leave it as console, it'll be in the console group.
I'm actually going to change that to user template.
And then you can give any description you want.
I'll just say Frank's console template.
That's it.
I'll select.
Okay.
And now we've got a new template that's stored.
So if I go back to my workspace and I want to create a new project now, we close all this up, I'm
going to right click and say New project.
And now you can go down to your templates and go down to your user templates right here.
And you should see that one we just created right here.
So we can just select that.
Next, I'll just say project one, select next, keep the defaults for the compilers and finish.
At this point you can double click here to make that project, the active project and we'll look at
the main CP.
You can see it's the main CP that we just typed.
Also, if you right click on the project and you go down to the settings, you can see a code completion
is C++ 14 and the global settings have the appropriate compiler flags that we need.
That's it.
We'll test this real quick.
That's run, build and execute.
And Hello World.
That's it.
So now you've got a project, you're all set up.
You can create as many of these as you like.
Tweak the settings as far as you like.
It's really up to you to decide what you want to do with the project templates.
But for this course include IO stream.
Give yourself a main.
You may or may not want this line right here since you know you're probably going to get rid of it anyway
when we start writing other code.
But at a minimum do something like that.
When you create a new project, you'll be ready to start coding.