Visual Studio Console Application

Just click the button below to start the whole online course!

Or use Facebook:

By registering you agree with our terms of use. You can read how we process your data.

Already have an account?

Lesson highlights

This video is for Seneca students to follow for installing Visual Studio 2017 and Creating Simple C and C console apps.Download Visual Studio:https://www.v. Today I created a new.NET Core console application in Visual Studio 2019 preview and added by code without a second thought. When I ran the application I was in for two surprises - the first was the icon had changed, to a fetching purple.

Are you looking for a quick reference on creating a C++ project in Visual Studio instead of a thorough-full lesson? Here it is:

  • Download Visual Studio Community Edition at https://www.visualstudio.com/…nity-vs.aspx
  • Run the installer, choose custom installation and check everything in the C++ group:
  • Run Visual Studio and select File -> New -> Project in the application menu:
  • Select the Visual C++ template -> Windows and in the next menu select Empty Project.
  • Edit the project name and location if needed and confirm the form.
  • Right-click the Source files folder in the Solution Explorer window on the right, and choose Add -> New Item:
  • Choose C++ File (.cpp) and name it Source.
  • Paste the Hello world program code in it:
  • Hit the green play button in the toolbar to run the project.

Would you like to learn more? A complete lesson on this topic follows.

In the previous lesson, Introduction to the C++ language, we talked about the language itself. Intoday's lesson, we're going to focus on the Visual Studio IDE. We'll show youhow to use it and program a simple console application.

IDE stands for Integrated Development Environment. In a nutshell, it's anapplication in which we'll write source code, and then use it to run, test anddebug our application.

Of course, we'll have to start by installing Visual Studio. If you haveaccess to paid versions, which come with advanced features, go ahead and usethem. However, the free Community version will be more than enough for us. Youcan download Visual Studio 2015 Community Edition from the officialMicrosoft site.

Installation

Even if English isn't your native language, I highly suggest installing theEnglish version of Visual Studio. The advantage to using English applications isthat if you run into problems, you will most likely not be able to find theanswers in your language (e.g. with advanced configurations). All of yourapplications and programs should also be written in English. For now, this isn'ta crucial step, so feel free to use your native language without using anyaccent characters, if your language has any. If you want to become aprofessional programmer, you should try to improve your language skills, andwrite everything in English.

The installation is very easy. Choose the Custom type when you executeit:

Then, check the Visual C++ group (everything in it) and do the same with theCommon Tools group.

You can install even more tools if you want, but this is all we're going toneed for this course. Either way, you'll be able to install additionalcomponents later if needed.

Note: Be careful with installing too many components, the installationmight take even up to several hours.

Then, we'll click 'Next', then 'Install', and wait...

After the installation, you may need to register your Visual Studio.Registration is free, after which you'll receive a serial number that allows youto use the program legally. Another option is to log in using your Microsoftaccount.

Note: Visual Studio is designed for developing Windows applications. Ifyou want to create applications for different operating systems (or to programon another operating system), use something like the NetBeans IDE. You candownload NetBeans from the official website oryou can use Eclipse.

Visual

Backup and version control

Programmers usually need a tool that will provide version control and abackup of their work. We can't rely on the fact that we simply save the programbecause we're humans and humans make mistakes. When you lose a few days' or evena few weeks' work, it can be really demotivating. It's good to think about suchsituations right from the start. I highly recommend Dropbox, which is extremelysimple, and automatically stores multiple versions of yourfiles, which makes it possible to revert to previous versions of the project,and also synchronizes with a web repository. Even if you'veaccidentally deleted your project, overwrote it, somebody stole your laptop oryour hard drive accidentally collapsed, your data will remain safe. Dropbox alsoallows you to share projects with several developers.

You can also use a tool called GIT for the same purposes, it can beintegrated into Visual Studio if you check the 'Git for Windows' option.However, its configuration would require the 'while' article. Dropbox is perfectfor our current intents and purposes.

Creating a project

Run Visual Studio and select File -> New -> Project in the applicationmenu.

In the New Project window, select the Visual C++ template -> Windows andin the next menu select Empty Project. Let's name this project'FirstApplication'. Create a folder for your projects in yourDropbox folder, for example, 'cpp/' (as in Plus Plus). Use theBrowse button and select a folder C:Usersyour_nameDropboxcpp.We will stick with console applications, the command line interface, for a whilebecause it needs minimal knowledge of the object-oriented world, and they areideal for learning the basics of the language. Confirm the form.

Visual Studio Tutorial

The window should now look like this (I have resized it to fit ):

A very important element in the window is the green 'Play' button in theupper bar, which compiles and runs our program. You man try it out, but ourprogram won't do anything. It'll simply terminate right away. You can also runthe program with the F5 keyboard shortcut. Shortcuts in VS aredesigned very well and they will simplify your work a lot. That is, if youdecide to learn them.

Near the arrow icon, we have Debug selected. This means that the program willbe compiled in Debug mode, and it'll contain certain routines to debug errors.It's mainly used to test the program while we're developing it, and the programmay run slower due to it. Once you're sure that your program is complete, switchit to Release mode and run the program. As a result, we'll have a program whichcan be distributed among people.

There is no code yet, so let's add some We'll click the right mousebutton on the 'Source files' folder in the Solution Explorer window, and chooseAdd -> New Item.

We'll choose C++ File (.cpp) and name it Source.

Studio

Directory structure of the console application

Let's take a look at what's in our application folder. Open it up, mine's inC:Usersyour_nameDropboxcppFirstApplication, and find a filenamed FirstApplication.sln. 'Sln' stands for ' Visual Studiosolution '. It's a set of projects and it may contain multipleapplications which are used for multi-tier applications, or for testing. We'llopen our applications using this file. There should also be a folder named'FirstApplication/' containing our project. Let's open it up, andsee what's inside.

The FirstApplication.vcxproj file contains a project file thatwe can use to open up our app. Source.cpp contains the actualsource code. You'll also see the Debug/ and Release/subfolders. There are .exe files of our application insideof it. That is, if we run the application at least once in thecorresponding mode. In order to show your application to others, the.exe file in the Release/ subfolder is the file youwould have to send them. Don't worry about any of the other files, for now.

Hello world

As tradition instructs, we'll make the first program most people make whenthey learn a new language - Hello World. This is a program that displays 'Helloworld' or some similar text.

The code will look like this:

Here's a detailed description of the code:

  • #include <iostream> attaches a library for console output (and input) to our project.
  • using namespace std simplifies command names from the iostream library. Without this line, we'd have to write to the console using the full form std::cout << 'Hello ICT.social!' << std::endl;.
  • int main(void) {} - Main() is a function, the main one. We'll learn to declare functions later. We write all the program code in its curly brackets block. The main() function is executed when the application starts.
  • cout << 'Hello ICT.social!' << endl; is how we print text to the console. We write text in quotes ('), to avoid C++ misinterpreting it as other commands. << endl prints the end of a line (breaks the line).
  • The << operator (after cout) 'sends' data to the console in this case
  • cin.get() waits for Enter to be pressed so the program is not terminated immediately.
  • return 0 - We terminate the program using the return command, 0 value tells the system that everything went fine. (If there is an error in the program, the value 1 is returned instead).

Now, run the program by pressing F5.

Congratulations, you have just become a programmer That will be all for today, inthe next lesson, Variables and the type system in C++, we'll look at the basic data types and create a simplecalculator.

Today's project is attached as a file at the end of the article. You couldalways download the result below each lesson. I suggest that you create aproject using the tutorial, and if something in your project doesn't work, thendownload it to find the mistake. If you download the lesson code before eventrying to make it yourself, you won't learn anything


Did you have a problem with anything? Download the sample application below and compare it with your project, you will find the error easily.

Download

Visual Studio Console Application Output

ConsoleBy downloading the following file, you agree to thelicense terms

Downloaded 4x (7.29 MB)
Application includes source codes in language C++

Do you like this article?
The author is a programmer, who likes web technologies and being the lead/chief article writer at ICT.social. He shares his knowledge with the community and is always looking to improve. He believes that anyone can do what they set their mind to.
David learned IT at the Unicorn University - a prestigious college providing education on IT and economics.

Changing a Windows App to a Console App in Visual Studio

In Visual Studio there are two kinds of *.exe binaries, a windows application and a console application. A Windows Application is a typical Windows program that has a GUI. Console applications, on the other hand, are supposed to be run from the console (i.e., they are DOS programs). For developers, the main difference is that a windows application's entry point is WinMain(), whereas a console application's entry point is main(). The start-up code is also different, so simply changing the name of the entry point will not change the type of application that is being made.

An elementary mistake to make, is to create a Windows application project when the intention was to create a console application. This mistake results in error messages such as:

MSVCRTD.lib(crtexew.obj) : error LNK2019: unresolved external symbol _WinMain@16 referenced in function ___tmainCRTStartup

When I made this mistake myself, a lengthy search on the internet brought solutions ranging from deleting the project and starting again (not nice at all) through to things that simply do not work. There is a much simpler way to fix this mistake. All that is required is knowing which options/settings to change. The following instructions are for Visual Studio 2008 Express. It will most likely work on other versions of Visual Studio too.

Switching from a Windows App to a Console App

  • In the 'Solution Explorer' (it should be in the left-hand side-bar), right-click on the project in question and select 'properties.'
  • Under 'Configuration Properties,' select 'Linker->System.'
  • Change the 'SubSystem' option from Windows (circled in red below) to console
  • The properties window should now look like:
  • Now select 'C/C++->Preprocessor,' saving the changes if requested
  • In the 'Preprocessor Definitions,' replace the entry '_WINDOWS' (circled in red below) with '_CONSOLE'

Visual Studio What Is A Console Application

  • The settings Window should now look like:

Visual Studio C# Console Application

  • Press'OK' to close the properties window
  • Done

Studio

Comments are closed.