[C ++] Chapter 1 describes how to use C ++ to compile console applications in VS2015 and Chapter 1st describes vs2015.

Source: Internet
Author: User

[C ++] Chapter 1 describes how to use C ++ to compile console applications in VS2015 and Chapter 1st describes vs2015.

Category: C ++, VS2015

Date created: 1. Introduction

Many people are still learning C ++ with VC 6.0 development tools. In fact, VC 6.0 development tools have been eliminated for a long time. This section only describes the two development tools recommended for learning C ++.

1. codeblocks 13.12

If you want the development tool to have a small capacity, we recommend that you use this tool. The installation program of this tool (version 13.12) is only 97.8 MB, but it is very powerful and suitable for teaching.

The installation program version for Windows is as follows:

Codeblocks-13.12mingw-setup.exe

2. VS2015 (comes with Update2)

If you want to learn the same development tool as you actually use, we recommend that you use this development tool. Although its installation file capacity is relatively large, it is actually used for development, so you can use it directly for actual projects after learning. Ii. Example 1 (Basic output)

The following is a simple example to illustrate how to use C ++ to write console applications in VS2015.

Example function: write a program to output all the daffodils. The number of daffodils refers to a three-digit number, and the cubes of each number are equal to this number. For example, 153 = 13 + 53 + 33.

1. Create a project

Run VS2015, select new project on the start page, and in the displayed new project window, choose other languages> C ++> Win32> Win32 console application, as shown in.

Enter the project name (for example, leleapplication1), select the project storage location (for example, E: \ MySource), and click OK. The following wizard window is displayed.

Click Finish to view the generated C ++ project solution.

2. write code

Change ConsoleApplication1.cpp to the following content:

// ----------------------------- // Write a program to output all the daffodils. The number of daffodils refers to a three-digit integer. The cubic sum of the numbers is equal to that number. // Example: 153 = 1*1*1 + 5*5*5 + 3*3*3 // ----------------------------- # include "stdafx. h "# include <iostream> using namespace std; int main () {int a, B, c; cout <" All daffodils: "<endl; for (int I = 100; I <= 999; I ++) {a = I/100; B = I % 100/10; c = I % 10; if (a * a + B * B + c * c = I) {cout <I <endl ;}} cout <"press enter to exit! "<Endl; getchar (); return 0 ;}

3. debug and run

Press <F5> to debug the operation.

During the first running, the following window is displayed:

This dialog box indicates that the code needs to be re-compiled. Check [do not show this dialog box], so that it will not be displayed after running. Click [Yes] (this means that you always re-generate the tool each time you press <F5> during debugging), and then you will see the following running interface:

Press enter to complete debugging.

4. Generate a 32-bit exe or a 64-bit exe

There are two generation methods for debugging: one is to generate 32-bit local code and the other is to generate 64-bit local code.

To generate 64-bit local code, click the drop-down box on the Right of x32 and select x64 as follows:

3. Example 2 (basic input)

Program function: enter two integers to display the sum of the two integers.

1. Create a project

Project name: leleapplication2

Template: Win32 console application

2. write code

Change ConsoleApplication2.cpp to the following content:

// Leleapplication2.cpp: defines the entry point of the console application. // Program function: enter two integers to display the sum of the two integers. # Include "stdafx. h "# include <iostream> using namespace std; int main () {int x, y; while (true) {cout <" enter two positive integers (separated by spaces ): "; cin> x> y; if (x <= 0 | y <= 0) {cout <endl <" is incorrect. Please enter it again. "<Endl ;}else {break ;}}cout <x <" + "<y <" = "<x + y <endl; cin. get (); cout <"press enter to exit! "; Getchar (); return 0 ;}

3. debug and run

Press the <F5> key to debug the operation. The effect is as follows:

Press enter to complete debugging. Iv. Code Format

Delete the last braces and re-type the braces to automatically adjust the code format.

Okay. Although the two examples are simple, they demonstrate the basic steps for compiling console applications in C ++ in VS2015. On this basis, you can continue to practice other examples.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.