Home PC Games Linux Windows Database Network Programming Server Mobile  
           
  Home \ Programming \ Acquaintance C ++: the most simple C ++ program     - Linux cron job (Linux)

- VNC configuration detailed analysis under Linux (Linux)

- Gitolite how to import other Git repositories (Server)

- Common Linux system performance monitoring command (Linux)

- Linux System Getting Started Learning: Change the name of the network interface on CentOS7 (Linux)

- Some safety precautions of Linux servers (Linux)

- Python format string (Programming)

- Linux command line under HTTP traffic sniffing tool: httpry (Linux)

- MySQL Slave synchronization problem solving (Database)

- Build ftp server under CentOS 6.5 (Server)

- GNU / Linux system, how to clean up memory space (Linux)

- MySQL concat function is SQL injection (Linux)

- VMware clone Linux find eth0 (Linux)

- A process of how to get the current traffic in GNU Linux (Linux)

- Android realize RippleEffect water (Programming)

- Oracle 12C RAC optimizer_adaptive_features cause of data into overtime (Database)

- secureCRT remote login Linux must first open the connection protocol (Linux)

- Linux Desktop allows exceptionally different launch applications (Linux)

- Python is not C (Programming)

- To compile and install Clang 3.5.0 in Linux CentOS (Linux)

 
         
  Acquaintance C ++: the most simple C ++ program
     
  Add Date : 2017-08-31      
         
         
         
  Let's write a simple C ++ program

// Helloworld.cpp
#include < iostream>

int main () {
    std :: cout < < "! Hello, Wrold" < < std :: endl;
    return 0;
}

This code reflects the four questions:
1. Comment
2. preprocessor directive
3.main () function
4. Input / output streams

The following will mainly talk about preprocessor directive: to generate a C ++ program has three steps. First, the code preprocessor runs preprocessor identification code meta information; then, the code is compiled into a computer can recognize object files; Finally, each object files are linked together to become an application . Preprocessing directives begin with the # character, such as #include < iostream>, meaning that tell the preprocessor: extract < iostream> header file for all the contents of the current file to use. < Iostream> header file declarations provided by the C ++ input / output functions, only this program includes header files, in order to complete the program you want to output Hello, World! text.

Note: The students know the familiar C header files .h is ending, such as < stdio.h>. In C ++, the standard header file .h suffix is omitted, such as < iostream>, but still contains the standard C header files, just change the name, such as the original < stdio.h> becomes < cstdio>.

There preprocessing directive # define, # ifdef, # ifndef, # endif like. E.g:

#ifndef MYHEADER_H
#define MYHEADER_H
// ...
#endif

This is to avoid duplicate sample include the header file.

To be mentioned here is that if the compiler supports the #pragma once directive, you can use this command instead of the above command:

#pragma once
// ...

Then briefly about the std :: syntax: std :: endl ending represents the output stream will wrap, as \ n characters. :: Is called the scope resolution operator, std refers to a namespace, use them together in order to resolve name conflicts between different code segments. For example, I write a piece of code, which defines a fun () function, but one day, I use third-party libraries, which happens to also defines a fun () function, then the compiler can not determine the code calls fun () function in the end belongs to which version. So I need to set your code into a namespace, we first define a namespace:

namespace mycode {
    void fun ();
}

When I use the fun () function when you need to specify its namespace, there are two ways:

using namespace mycode;

int main () {
    fun (); // call is my own definition of fun () function
    return 0;
}

or:

int main () {
    mycode :: fun (); // call is fun my custom () function
    return 0;
}

Now I understand, cout output stream belongs to namespace std, so write std :: cout. Incidentally, also belong to the input stream cin std namespace as for use, this is not to mention.
     
         
         
         
  More:      
 
- Ubuntu / openSUSE users to install Veusz 1.21.1 (Linux)
- ORA-38856: Unable instance UNNAMED_INSTANCE_2 (redo thread 2) marked enabled (Database)
- About phpwind 5.01-5.3 0day analysis of the article (Linux)
- CentOS 7 - use cgroups limit process resource (Linux)
- Java 8 stream parsed into SQL (Programming)
- JavaScript, some conclusions about the implicit conversion (Programming)
- C ++ inheritance and derived (induction principle) (Programming)
- File SUID, SGID, Sticky property (Linux)
- Killall five options you might not know (Linux)
- Linux environment MySQL master-slave synchronization (Database)
- How to configure MariaDB replication in CentOS Linux (Database)
- DDOS Attacks and Prevention (Linux)
- Linux CPU Monitoring Index (Linux)
- WEB-based Android Remote Tools Python implementation (Programming)
- Linux crontab command format example (Linux)
- MongoDB 3.2 to upgrade from 3.0.7 (Database)
- Oracle RAC 10.2.0.5 upgrade to 11.2.0.4 problems encountered (Database)
- Shell command line operation (Linux)
- Nagios (centreon) monitoring Linux Log (Server)
- Linux variable learning experience (Linux)
     
           
     
  CopyRight 2002-2022 newfreesoft.com, All Rights Reserved.