Indispensable Windows Native (11), windowsnative

Source: Internet
Author: User

Indispensable Windows Native (11), windowsnative

[Download source code]


Windows Native (11)-C ++: hello c ++. Differences between C ++ and C



Author: webabcd


Introduction
Windows Native C ++ is indispensable

  • Hello c ++
  • Differences between C ++ and C



Example
1. hello c ++
CppHello. h

// Ensure that the file is compiled only once (even if it is referenced multiple times, it is compiled only once) /** # The ifndef method depends on the macro name and cannot conflict * # pragma once ensures that the same file will not be compiled multiple times, the "same file" here refers to a physical file * # pragma once depends on the compiler; # ifndef is naturally supported by the Language */# pragma once // contains the specified header file/** For example: * <string. h> is the file in the c standard library * <cstring> contains the string in the c standard library. h file, which is placed under the namespace std * <string> is the string class of the c ++ standard library, under the namespace std */# include <string> // reference the namespace std (std-standard) using namespace std; // custom namespace NativeDll {class CppHello {public: string Hello (string name );};}

CppHello. cpp

/** Hello c ++ */# include "pch. h "# include" CppHello. h "// The namespace using namespace NativeDll defined in the header file; // implement the function in the header file (previously using namespace NativeDll;) string CppHello: Hello (string name) {return "hello:" + name;}/* What is compilation? 1. In order to enable the computer to execute the high-level language source program, the compiler (complier) must be used to translate the source program into a binary program (object program) 2. Compilation is based on the source program files, and the target program generally uses. obj or. o as the suffix (object abbreviation) 3. After obtaining multiple target files, you need to use the Connection Program (linker) connect all the target programs of a program with the library files of the system and other information provided by the system to form an executable binary file */


2. Differences between C ++ and C
CppDiff. h

#pragma once #include <string>using namespace std;namespace NativeDll{    class CppDiff    {    public:        string Demo();    };}

CppDiff. cpp

/** Differences between C ++ and C language **/# include "pch. h "# include" CppDiff. h "using namespace NativeDll; struct birth {int year; int month; int day ;}; string CppDiff: Demo () {/* I am a multiline annotation. ANSI C only supports multiline annotation, the single line comment is not supported * // I am a single line comment \ if the single line comment ends with "\", the next line is also a comment \ multiple lines comment "/**/" is not supported nested, however, there can be a single line comment/* void fun (); // This sentence in C indicates that any parameter can be passed, this sentence in C ++ means that no parameter void fun (void) can be passed; // This sentence in C language means no parameter can be passed, therefore, it is recommended that you use void * // C ++ to obtain the address of the register variable when there is no parameter in the C language, but the compiler will change it to a memory variable (because the register variable has no address) /* the C language regards the character as the int Type C ++ and regards the character as the char type, for example, sizeof ('A ') ANSI C99 regards it as the int type (the 32-bit machine generally uses the int to occupy 4 bytes), so it returns the 4 iso c ++ and regards it as the char type, it occupies 1 byte. Therefore, when bool type bool B = true is added to the basic data type of 1 * // C ++, the C language must be the "struct name variable name". In C ++, struct can omit the comma expressions connected by the comma operator, an expression is solved in sequence by an expression. The value of the entire expression is the value of the last expression (note that the comma operator level is the lowest and should be enclosed in parentheses) int x = (x = 1, x + = 1, ++ x); // 3 int y = (y = 1, y + = 1, y ++); // 2 // std :: string can be used to easily copy and splice strings. std: string str1 = "webabcd"; std: string str2 = "wanglei"; std :: string str3 = str1; // copy the string, equivalent to strcpy str1 = "lalala"; // changing str1 will not affect str3 std :: string str4 = str1 + "" + str2 + "" + str3; // string concatenation simple return "read code and comment ";}



OK
[Download source code]

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.