domingo, 30 de mayo de 2021

How to set up a new C++ project in Visual Studio 2019

1. Download and execute the Visual Studio Community 2019 Installer from the Microsoft website. Then select Visual Studio Community 2019 and click on the Install button. If you already installed Visual Studio 2019, you can move on to step 4.


2. You will be asked to select the packages you want to install. This tutorial is for C++ but you can select other packages if you like. The basic C++ package you should install is the one called "Desktop development with C++" (which is not necessarily for desktop only as I use it to develop for other platforms too).


2.1 I recommend to also go to the Individual components tab and select the Git extension and Git for Windows:




3. After installing, a menu will let you choose Visual C++ as your default setting. *



4. A folder will be needed where our development solutions will be placed. I called mine just "solutions".



5. You can then create a new solution and project as follows:
5.1 Open Visual Studio 2019 and click on Create a new project.



5.2 Select Windows Desktop Wizard as project template, then click on Next




5.3 Then type the Project name (such as MyFirstProject) and the name of the folder in the "Location"  box, then click on Create



5.4 In the window that pops-up next, select "Console Application" as the Application type and check the Empty Project checkbox.



5.5 Click on OK and the project and project files will be created automatically as shown below.





6. After setting up the project, you will be able to add files to it from the samples you find here or browsing the web. If  you want to test some code you can write a hello world example as follows:

6.1 Right click on the project name in the Solution Explorer in Visual Studio (at the right or left of the edit area) and in the pop-up menu select Add -> New item



6.2 Select Visual C++ -> C++ file (.cpp) and type the name of the file, such as "main.cpp" at the name box. Then Click on "Add" to create the file.




6.3 Type or copy the following code into the main.cpp file:

#include <stdio.h>

int main()
{
    printf("Hello world!\n");
    return 0;
}



6.4 Press F7 (or ctrl+shift+b if you didn't set up Visual C++ settings) to build the executable and F5 to execute in debug mode. 





For starting coding in your new project, you can continue reading the next tutorial which explains the basic structure of a C/C++ program.

If you didn't set up Visual C++ settings during install you can do it later by going to menu tools -> import and export settings -> reset all settings and the option will appear again. The screenshot shown is from that window because I had no fresh install of Visual Studio to see the window appear during the first run.

How to set up a new C++ project in Visual Studio 2017

1. Download and execute the Visual Studio Community 2017 Installer from the Microsoft website. Then select Visual Studio Community 2017 and click on the Install button. If you already installed Visual Studio 2017, you can move on to step 4.


2. You will be asked to select the packages you want to install. This tutorial is for C++ but you can select other packages if you like. The basic C++ package you should install is the one called "Desktop development with C++" (which is not necessarily for desktop only as I use it to develop for other platforms too).


2.1 I recommend to also go to the Individual components tab and select the Git extension and Git for Windows:




3. After installing, a menu will let you choose Visual C++ as your default setting. *



4. A folder will be needed where our development solutions will be placed. I called mine just "solutions".



5. You can then create a new solution and project as follows:
5.1 Open Visual Studio 2017 and go to menu File -> New -> Project.



5.2 Select Visual C++ -> Windows Desktop -> Windows Desktop Wizard. Then type the name of the project and the name of the folder in the "Location" box, then click on OK. Another window will show more options.



5.3 Select "Console Application" as the Application type and check the Empty Project checkbox.



5.4 Click on OK and the project and project files will be created automatically as shown below.





6. After setting up the project, you will be able to add files to it from the samples you find here or browsing the web. If  you want to test some code you can write a hello world example as follows:

6.1 Right click on the project name in the Solution Explorer in Visual Studio  (at the right or left of the edit area) and in the pop-up menu select Add -> New item



6.2 Select Visual C++ -> C++ file (.cpp) and type the name of the file, such as "main.cpp" at the name box. Then Click on "Add" to create the file.




6.3 Type or copy the following code into the main.cpp file:

#include <stdio.h>

int main()
{
    printf("Hello world!\n");
    return 0;
}



6.4 Press F7 (or ctrl+shift+b if you didn't set up Visual C++ settings) to build the executable and F5 to execute in debug mode. 





For starting coding in your new project, you can continue reading the next tutorial which explains the basic structure of a C/C++ program.

If you didn't set up Visual C++ settings during install you can do it later by going to menu tools -> import and export settings -> reset all settings and the option will appear again. The screenshot shown is from that window because I had no fresh install of Visual Studio to see the window appear during the first run.

How to set up a new C++ project in Visual Studio 2013

- Download and install Visual Studio 2013 (Express or the version you like) from the Microsoft website (it's free to try), preferably the latest Visual Studio you can find (such as VS2019--ie. not VS2013).  I recommend downloading it in English because all the references on the internet and here are mostly in English.
- After installing, a menu will let you choose Visual C++ as your default setting. *
- A folder will be needed where our development solutions will be placed, which I often call "Dev" because it's short and straightforward.
- You can then create a new solution and project as follows:

  -- Open Visual Studio 2013
  -- Go to menu File -> New -> Project.
  -- Select Visual C++ -> Win32 -> Win32 Console Application
  -- Type the name of the project and the name of the folder in the "Location" box, then click on OK. Another window will show more options.
  -- Select "Application Settings" and check the Empty Project checkbox.
  -- Click on Finish and the project and project files will be created.

After that you will be able to add files to this new project from the samples you find here or browsing the web. If  you want to test you can write a hello world as follows:

 - Right click on the project name in the Solution Explorer in Visual Studio  (at the right or left of the edit area)
 - Select Add -> New item
 - Select Visual C++ -> C++ file (.cpp)
 - Type the name of the file, such as "main.cpp" at the name box.
 - Click on "Add" to create the file.
 - Then type the following code into the main.cpp file:

#include <stdio.h>

void main()
{
    printf("Hello world!\n");
}



 - Press F7 (or ctrl+shift+b if you didn't set up Visual C++ settings) to build the executable and F5 to execute in debug mode. Press Ctrl+F5 to execute without closing the console window after execution so you can see the program output.

For starting coding in your new project, you can continue reading the next tutorial which explains the basic structure of a C/C++ program.

* If you didn't set up Visual C++ settings during install you can do it later by going to menu tools -> import and export settings -> reset all settings and the option will appear again.