1.C++ 程序能夠定義爲對象的集合,這些對象經過調用彼此的方法進行交互。如今讓咱們簡要地看一下什麼是類、對象,方法、即時變量。html
2.C++語言結構: ios
#include <iostream> using namespace std; // main() 是程序開始執行的地方 int main() { cout << "Hello World"; // 輸出 Hello World return 0; }
(1)C++ 語言定義了一些頭文件,這些頭文件包含了程序中必需的或有用的信息。上面這段程序中,包含了頭文件 <iostream>。c++
(2)下一行 using namespace std; 告訴編譯器使用 std 命名空間。命名空間是 C++ 中一個相對新的概念。其餘的在後面會介紹。編程
C++ 標識符是用來標識變量、函數、類、模塊,或任何其餘用戶自定義項目的名稱。一個標識符以字母 A-Z 或 a-z 或下劃線 _ 開始,後跟零個或多個字母、下劃線和數字(0-9)。app
C++ 標識符內不容許出現標點字符,好比 @、& 和 %。C++ 是區分大小寫的編程語言。所以,在 C++ 中,Manpower 和 manpower 是兩個不一樣的標識符。編程語言
下面列出幾個有效的標識符:函數
mohd zara abc move_name a_123
myname50 _temp j a23b9 retVal
下表列出了 C++ 中的保留字。這些保留字不能做爲常量名、變量名或其餘標識符名稱。ui
asm | else | new | this |
auto | enum | operator | throw |
bool | explicit | private | true |
break | export | protected | try |
case | extern | public | typedef |
catch | false | register | typeid |
char | float | reinterpret_cast | typename |
class | for | return | union |
const | friend | short | unsigned |
const_cast | goto | signed | using |
continue | if | sizeof | virtual |
default | inline | static | void |
delete | int | static_cast | volatile |
do | long | struct | wchar_t |
double | mutable | switch | while |
dynamic_cast | namespace | template |
只包含空格的行,被稱爲空白行,可能帶有註釋,C++ 編譯器會徹底忽略它。this
在 C++ 中,空格用於描述空白符、製表符、換行符和註釋。空格分隔語句的各個部分,讓編譯器能識別語句中的某個元素(好比 int)在哪裏結束,下一個元素在哪裏開始。所以,在下面的語句中:spa
int age;
在這裏,int 和 age 之間必須至少有一個空格字符(一般是一個空白符),這樣編譯器纔可以區分它們。另外一方面,在下面的語句中:
fruit = apples + oranges; // 獲取水果的總數
fruit 和 =,或者 = 和 apples 之間的空格字符不是必需的,可是爲了加強可讀性,您能夠根據須要適當增長一些空格。
本文大部份內容源自菜鳥教程的c++教程原文網址爲:www.runoob.com/cplusplus/cpp-basic-syntax.html