- [Instructor] In this movie, I'll show you
how to use Windows with Microsoft Visual Studio
to follow the exercises in this course.
For the exercises in this course
you'll need a development environment.
That includes a modern C++ compiler
that supports the features of the current C++ standard.
This machine is running the latest version of Windows 10
as of Summer 2020, and I've installed the 2019 edition
of Visual Studio Community edition,
which is the latest version available
as I record this course.
You don't have to use Visual Studio with this course.
You may use any development environment you like
as long as it includes a conforming C++ compiler.
There are usually several editions of Visual Studio
and some of them will have what you need
and some of them won't.
Under Visual Studio here,
You see there's a Community edition.
The Community edition is a good choice
if you don't have one of the paid edition
has most of the features of the professional edition
and it's available for free from Microsoft.
If you have one of the paid additions of Visual Studio,
and it includes the current C++ compiler,
then you may certainly use that.
Older versions of Microsoft C++ compiler
may work for most of the course.
Just know that some of the exercises
may not work with an older compiler.
Microsoft Visual C++ Version 1926
or later, should have all the features you need.
And I'll show you how to check the compiler version
in this movie.
That's the version that's installed as of right now,
the latest community edition
that's Microsoft C++ Version 1926.
So I've already installed the Community edition
of Visual Studio on this computer
and I've already downloaded the exercise files
to my desktop here.
So I'm going to go ahead and open Visual Studio
and I'm going to select create a new project.
And under create a new project,
I'm going to select empty project.
You don't want console app, even though
we're going to be building console applications.
But a Microsoft console app includes
Microsoft specific code and actually all of these
other options will include Microsoft specific code.
And what we're trying to do here is learn the standard C++.
And so we're going to start with an empty project
for that purpose and I'll select Next.
I'm going to name my project working cause I just think
that's a fabulous name for things like this.
And for the location, I'm going to come out here
and I'm going to go to my documents folder,
and you see it's already created
this Visual Studio 2019 folder, which is empty
and I could put it in there, but I'm contrarian.
And so I'm going to create a new folder,
I'm going to call it Cpp essential training,
This is how I spell it, C++ essential training.
And I'll select that and I'll say select folder.
It really doesn't matter that much
as long as you know where you've put this
and, I like project-specific folders
and so that's what I'm doing anyway.
Under solution name, you want to leave that as working
and you want to select place solution
and project in the same directory.
And so I'll go ahead and I'll select create.
And there we have it, it says it's creating the project
and it's created it successfully.
So here we have our new working project and you notice
that it has all of these different places for things.
And so I'm going to go ahead and make sure
that the project itself is selected.
So not the solution, the project.
And not any of these folders here
are the one that says working like this.
We want to have that selected, and we're going to
set up the compiler for the current standard.
Now, these settings are per project.
So if you start a new project, you need to set them again.
So we're going to be using this project
for the whole of this course
for all the exercises of this course,
we use this same project.
We'll just swap out the source files.
And that works really really great.
So the first thing we're going to do
is we're going to add an existing item.
So if I right click on this, you see down here, I have add
and I have existing item and you see,
it says Shift + Alt + A.
So I can use Shift + Alt + A or I can just select this here
and it'll give us an opportunity to add an existing item
to our project.
So I'm going to come over here to the exercise files
and select chapter two.
And we're going to find hello.cpp, this one right here.
And I'm going to make a working copy of this,
so I hold down the Control key,
while I just drag it a little bit
and it makes a copy and it names it copy.
So I can leave that name alone.
Or if I want to, I can call it hello-working
or whatever I want to do with that.
And so here's my working copy.
I can double-click on that
or I can select it and select add.
And then we have it now, it's added to our source files.
And if I select that you see there is the source file
and you may or may not have this bottom panel here.
And that's alright, it'll show up when we compile
but there's our source file for hello.cpp.
Now, again I'm going to select working here
and that's important.
These steps will not work properly
if you don't have working selected.
And so with working selected, under project properties
and if I don't have working selected
I won't get the same thing so
it's a little bit weird like this and I think
we may be able to get it by right clicking on working.
Yeah, they're on their properties.
So that gets us to the same place.
And that's where we want to be.
So the first thing I'm going to do here
is I'm going to go into C++ and preprocessor.
And you notice there's some preprocessor definitions here.
And if I select that, I got this little dropdown
and I can say edit.
And that allows me to edit the preprocessor definitions.
And there's a couple of things that we're going to
want to add here.
So the first thing is and you've got to spell this
exactly properly or it doesn't do what it needs to do.
So be careful with your spelling, _CRT
which stands for C Runtime.
CRT underscore the word secure underscore
no underscore warnings equals one.
Here's what this does, normally Microsoft C++ compiler
will generate warnings when you use
some standard C++ library functions.
And there's a lot of history behind why this is,
it's not because Microsoft is evil or anything.
It's just that their C compiler
is much much older than the standard
and they're trying to not break
like really really old legacy code.
And some of us may or may not agree with that choice
but that's what their choice is.
So if you want the standard you need to
instead add a couple of preprocessor definitions
so that you can use standard functions instead
of the Microsoft-specific functions.
And this is just because they have such a long legacy
with their compiler.
So it's not really an evil thing
although some people choose to think of it that way.
So this course is designed to teach the standard C++
and these functions are part of the standard.
Microsoft has their own versions
of many of these standard functions.
You can certainly use those if you prefer
but the purpose of this course is the standard.
So you'll need to be able to use the standard functions
for this course.
And this setting allows you to do that
without generating error messages.
And then the second one we need to add here is
underscore has, the word has, and this is all caps.
These all have to be all caps or again
they don't work the C++ preprocessor
which is the same as the C preprocessor, is case sensitive.
So lowercase will not work,
these all have to be capital letters.
Has underscore iterator underscore debugging equals zero.
This one actually gets around a little bug
in Microsoft's implementation of STL iterators.
And again, because they're so tied to their legacy.
They've decided to keep that bug
and give us a preprocessor definition to get around it.
And so these are the things we're adding when we say, okay
we'll see that these are now added
to this preprocessor definitions
and we select apply and then we come over here
under C++ language, under C++ language standard.
I want to grab this dropdown here and you want to select
the latest standard you can.
C++17 would probably work just fine for this course
but I'm just going to select the preview features
from the latest C++ working draft which is C++20.
It hasn't been approved yet
and most of the features aren't even implemented.
But this gives you like everything up to the very latest,
which is just fine.
And again, I'm going to select apply
and will wait for the spinning ball to finish.
And then we'll just come down here and select okay.
Now, one final thing we want to do here,
We want to come under Tools here and under Options.
And I'm not sure if this is something that I did
or if it's part of the standard installation or not,
but here under keyboard, we're going to look for a command
that includes the word, clean solution
clean solution like that.
And you'll find this Build.CleanSolution.
And if this says Ctrl + Alt + F8,
or another keyboard shortcut that you like, that's fine.
And if it's not there, then you're going to want to add it.
So I'm going to go ahead and remove this
and I'm going to add it Ctrl + Alt + F8.
So I put my cursor in here and I press those keys
and I get that in there and I select assign.
And so now Build.CleanSolution
is assigned to Ctrl + Alt + F8,
and says global because this is in the global here.
So if that was already there
you don't need to remove it and add it.
I just want to show you how you add it,
cause it's a little weird.
And so we'll say, okay, we're going to use that
as we go along here.
And so now we're going to go ahead and we're going to compile
this hello.cpp or hello.working.cpp.
Now, these exercises for this course
are very simple C++ programs.
They run from the command line
without any Graphical User Interface.
Programs that use a Graphical User Interface
tend to have a lot of quotes to support the display,
and that is OS specific.
In other words, the graphical user interface
for Windows is not going to be the same
as the graphical user interface for Mac
or for Linux or for any other operating system.
And so, again, we're just trying to teach you
the C++ standard.
And so command line programs is the easy way to do that.
So these exercise files are command line programs
and they're very simple and they're very uncluttered
so you can focus on the part of the language
that you're learning.
So here's how we compile and run these
simple C++ programs in Microsoft Visual Studio.
So if I come up here under build, you'll see,
it says build solution is F7.
And my cursor can be anywhere.
It can be anywhere in the project and I press F7
and down here, you see, it says, build starting
and it's compiling that file.
And it is created this working.exe.
And it's put it here in our documents folder under cppst
under the working project under debug and working now,
I could copy all of that and paste it into a CD command
in my PowerShell, or, and here's the easy thing to do.
I come up here under Tools, and under command line
and I can either run the command prompt
or I can run Developer shell.
I liked Developer Shell, but I'm an old Unix guy.
So that's more familiar to me.
You can use either one of these,
but I'm going to come under here, under PowerShell.
And this puts me in the project directory
the working directory, if I type dir,
you see, there's my debug folder,
which is where my executable is
and here's all the project-related files
that we don't really have to do anything with.
So I'm just going to say cd debug.
And of course this is Windows, so it's not case sensitive.
And then under debug, you see, I have my working.exe
and so I want to run that, which I just compiled over here
and so I want to run that and I just say ./
or you can use a backslash which is more Windows C
PowerShell will accept either.
And I just say working like that and press Enter,
and it runs, my hello world.
And so here's my code, which has puts hello world
and I've compiled it and I've run it in the Powershell.
So this is how we run something in Microsoft Visual Studio.
This is how we run a command line program
in Microsoft Visual Studio.
Microsoft Visual Studio doesn't have a way
to run them down here in the little output,
that would be a whole lot more convenient.
And that's actually how exe code works on a Mac.
But on Windows, this is the way that we do it
we run it in a PowerShell or in a command exe,
and that works just great.
So the purpose of a hello world program
is really just to test your developer chain.
And so we're able to load up the source code,
we're able to compile it, we're able to run it.
And that works great, so we're done with hello now.
And so I'm just going to come over here and delete it
with the Delete key on my keyboard.
And we're going to load a different item,
so Shift + Alt + A and this allows to load a different file
from our exercise files.
And I want to bring up cpp11, this test
to make sure this compiler will run
the latest features in the C++ language.
And so I'm going to make a working copy of it here
and I'm going to load that up here, we have cpp11 copy,
and here's the code and I press F7 to compile it.
And you see it's compiled successfully.
And I can come over here to our PowerShell
and just press my Up arrow and select working.
And there I get the output.
And what it's done here is it's using new features in C++
from C++11, it's got an initializer list
and it's using this new type of For-loop
and it's doing all of these things
and it's printing out these values.
And so that's great.
That's working exactly as we expect.
So one more thing we want to do here
is we want to make sure we can actually edit our code
and add some code to it, so I'm going to come in here
and I'm going to print the version of the compiler,
and that looks like this.
And again, you haven't learned all of this code yet,
and that's fine.
Just type what I'm typing
and you'll see that it compiles and works,
and we're going to learn how all of this works later.
But for right now, we'll want to put some quotes here.
And we want to say, MSC Microsoft C version is %d\n.
And that gives us an integer value and a new line.
And then comma, and the value that we're going to
put there is MSC_VERSION and so we can just select it here
we can type that much of it and we can select it.
And then we need a semicolon at the end of our line.
And again, we'll learn all the syntax of C++
in a little bit here later in this chapter.
And so save it with Ctrl + S
and function key F7, to compile it.
You notice it is compiled down here successfully.
And we come over here to our PowerShell
and Up arrow and there it is,
we see, we have Microsoft C Compiler Version 1926
which is the latest version as of the time
that I'm recording this.
So now that we've done all of this,
and it's all working as we expect,
we can delete this file, press the Delete key here,
and I want to clean and so if I come under build here
you see Clean Solution has this Ctrl + Alt + F8
that we configured.
And so I'm going to press Ctrl + Alt + F8
and it cleans the solution.
And so if we come out here to our file explorer
we can take a look at this, go into documents
and cppest and our working project.
And under debug, you see that now there's nothing in there.
And if we go into our Developer shell and we type dir,
we see that the executable is gone.
All of our intermediate files are gone
because we have cleaned the solution.
And this allows us to start
from a clean place with each lesson.
And so now you have a clean working development environment
for following the exercises in this course.
I know this took a little bit of time.
I hope you paid attention to the details.
Maybe you even learned a little bit
about how all of this works
and now we can go ahead and continue
with the rest of this course.