C++轉義字符 & 關鍵字

轉義字符

換行符 \n   水平製表符\t
縱向製表符 \v 退格符 \b
回車符 \r   進紙符 \f
報警(響鈴)符 \a 反斜線 \\
疑問號 \? 單引號 \'
雙引號 \"  


關鍵字

asm  =>__asm auto bad_cast bad_typeid
bool break case catch
char class const const_cast
continue default delete do
double dynamic_cast else enum
except explicit extern false
finally float for friend
goto if inline int
long mutable namespace new
operator private protected public
register reinterpret_cast return short
signed sizeof static static_cast
struct switch template this
throw true try type_info
typedef typeid typename union
unsigned using virtual void
volatile while    

關鍵字是預先保留的標識符,每個關鍵字都有特殊的含義。我們不能在程序中使用與關鍵字同名的標識符。以下是C++所保留的關鍵

C++關鍵字全集(這個是從C++ Primer copy過來的,有一些補充,也有一些已經被替代):

(1)asm
asm已經被__asm替代了,用於彙編語言嵌入在C/C++程序裏編程,從而在某些方面優化代碼.雖然用asm關鍵

字編譯時編譯器不會報錯,但是asm模塊的代碼是沒有意義的.

(2)auto 
這個這個關鍵字用於聲明變量的生存期爲自動,即將不在任何類、結構、枚舉、聯合和函數中定義的變量

視爲全局變量,而在函數中定義的變量視爲局部變量。這個關鍵字不怎麼多寫,因爲所有的變量默認就是

auto的。

(3)bad_cast,const_cast,dynamic_cast,reinterpret_cast,static_cast
關於異常處理的,還不是太瞭解..

(4)bad_typeid
也是用於異常處理的,當typeid操作符的操作數typeid爲Null指針時拋出.

(5)bool
不用多說了吧,聲明布爾類型的變量或函數.

(6)break
跳出當前循環.The break statement terminates the execution of the nearest enclosing loop or

conditional statement in which it appears.

(7)case
switch語句分支.Labels that appear after the case keyword cannot also appear outside a

switchstatement.

(8)catch,throw,try
都是異常處理的語句,The try, throw, and catch statements implement exception handling.

(9)char
聲明字符型變量或函數.

(10)class
聲明或定義類或者類的對象.The class keyword declares a class type or defines an object of a

class type.

(11)const
被const修飾的東西都受到強制保護,可以預防意外的變動,能提高程序的健壯性。它可以修飾函數的參

數、返回值,甚至函數的定義體。 
作用: 
1.修飾輸入參數 
      a.對於非內部數據類型的輸入參數,應該將“值傳遞”的方式改爲“const引用傳遞”,目的是提

高效率。例如將void Func(A a) 改爲void Func(const A &a)。 
      b.對於內部數據類型的輸入參數,不要將“值傳遞”的方式改爲“const引用傳遞”。否則既達不

到提高效率的目的,又降低了函數的可理解性。例如void Func(int x) 不應該改爲void Func(const int

&x)。 
2.用const修飾函數的返回值 
      a.如果給以“指針傳遞”方式的函數返回值加const修飾,那麼函數返回值(即指針)的內容不能

被修改,該返回值只能被賦給加const修飾的同類型指針。 
如對於:const char * GetString(void); 
如下語句將出現編譯錯誤: 
char *str = GetString();//cannot convert from 'const char *' to 'char *'; 
正確的用法是: 
const char *str = GetString(); 
      b.如果函數返回值採用“值傳遞方式”,由於函數會把返回值複製到外部臨時的存儲單元中,加

const修飾沒有任何價值。 如不要把函數int GetInt(void) 寫成const int GetInt(void)。 
3.const成員函數的聲明中,const關鍵字只能放在函數聲明的尾部,表示該類成員不修改對象. 
說明: 
const type m; //修飾m爲不可改變 
示例: 
typedef char * pStr; //新的類型pStr; 
char string[4] = "abc"; 
const char *p1 = string; 
p1++; //正確,上邊修飾的是*p1,p1可變 
const pStr p2 = string; 
p2++; //錯誤,上邊修飾的

是p2,p2不可變,*p2可變 
同理,const修飾指針時用此原則判斷就不會混淆了。

const int *value; //*value不可變,value可變 
int* const value; //value不可變,*value可變 
const (int *) value; //(int *)是一種type,value不可變,*value可變 
//邏輯上這樣理解,編譯不能通過,需要tydef int* NewType; 
const int* const value;//*value,value都不可變

(12)continue
結束當前循環,開始下一輪循環.Forces transfer of control to the controlling expression of the

smallest enclosing do, for, or while loop.

(13)default
switch語句中的默認分支.None of the constants match the constants in the case labels;

adefault label is present.Control is transferred to the default label.

常量的無匹配情況下標籤的常量;
adefault標籤present.Control轉移到默認的標籤。


(14)delete
經常用於動態內存分配的語句,Deallocates a block of memory.


(15)do
在do-while循環結構中開始循環體.Executes a statement repeatedly until the specified

termination condition (the expression) evaluates to zero.

(16)double
聲明雙精度變量或函數.

(17)else
條件語句否定分支(與 if 連用).

(18)enum
聲明枚舉類型.The name of each enumerator is treated as a constant and must be unique within

the scope where the enum is defined.

(19)explicit

This keyword is a declaration specifier that can only be applied to in-class constructor

declarations. An explicit constructor cannot take part in implicit conversions. It can only

be used to explicitly construct an object.
這個關鍵字聲明說明符,可以只適用於同類構造函數聲明。顯式構造函數不能在隱式轉換的一部分。它只

能用於顯式構造一個對象

(20)export
MSDN只說The export keyword is not supported on templates.一種導出語句吧..

(21)extern
extern 意爲“外來的”···它的作用在於告訴編譯器:有這個變量,它可能不存在當前的文件中,但

它肯定要存在於工程中的某一個源文件中或者一個Dll的輸出中。聲明變量是在其他文件中聲明(也可以看

做是引用變量).Objects and variables declared as extern declare an object that is defined in

another translation unit or in an enclosing scope as having external linkage.

(22)false,true
bool類型的兩個枚舉值.

(23)float
聲明浮點型變量或函數.

(24)for
一種循環語句(可意會不可言傳).Use the for statement to construct loops that must execute a

specified number of times.

(25)friend
聲明友元函數或者類.The friend keyword allows a function or class to gain access to the

private and protected members of a class.

(26)goto
無條件跳轉語句.Performs an unconditional transfer of control to the named label.

(27)if
條件語句.Controls conditional branching.常與else一起用.

(28)inline
聲明定義內聯函數,編譯時將所調用的代碼嵌入到主函數中.The inline specifiers instruct the

compiler to insert a copy of the function body into each place the function is called.

(29)int
聲明整型變量或函數.

(30)long
聲明長整型變量或函數.

(31)mutable

This keyword can only be applied to non-static and non-const data members of a class. If a

data member is declared mutable, then it is legal to assign a value to this data member from

aconst member function.
這個關鍵字只適用於非靜態和非const數據類成員。如果一個
聲明數據成員是可變的,那麼它是合法的賦值從這個數據成員
aconst成員函數


(32)namespace

Dynamically imports an element behavior into a document.
動態導入到文檔中的元素行爲
c++中using namespace std


(33)new
動態內存分配.Allocates memory for an object or array of objects of type-name from the free

store and returns a suitably typed, nonzero pointer to the object.
分配內存的對象或數組類型的對象從自由的名義
存儲和返回一個適當類型,非零對象的指針


(34)operator
The operator keyword declares a function specifying what operator-symbol means when applied

to instances of a class. 
經營者關鍵字聲明一個函數指定經營什麼符號意味着當應用
對一類的實例

(35)private

類私有函數和數據成員的標示.When preceding a list of class members, the private keyword

specifies that those members are accessible only from member functions and friends of the

class. This applies to all members declared up to the next access specifier or the end of

the class.
當上一類的成員,私人關鍵字列表
指定這些成員只能從成員的職能和朋友訪問
類。這適用於所有成員宣佈了下一個訪問符或結束

(36)protected
The protected keyword specifies access to class members in the member-list up to the next

access specifier (public or private) or the end of the class definition. 
受保護的關鍵字指定訪問類成員的成員名單,直至下一個
訪問說明符(公共或私營)或類定義結束

(37)public

訪問方式:When preceding a list of class members, the public keyword specifies that those

members are accessible from any function. This applies to all members declared up to the

next access specifier or the end of the class.
當上一類成員,市民關鍵字列表指定的
成員可以從任何功能。這適用於所有成員宣佈到
明年訪問符或類的結束


(38)register 
聲明積存器變量.The register keyword specifies that the variable is to be stored in a machine

register, if possible.這個關鍵字命令編譯器儘可能的將變量存在CPU內部寄存器中,而不是通過內存尋

址訪問,從而提高效率。 
登記冊關鍵字指定變量是要在計算機中存儲的
註冊,如果可能的話

(39)return
子程序返回語句(可以帶參數,也看不帶參數),返回函數調用點.Terminates the execution of a

function and returns control to the calling function (or, in the case of the main function,

transfers control back to the operating system). Execution resumes in the calling function

at the point immediately following the call.
終止執行的
功能及控制返回給調用函數(或者,在主函數的情況,
傳輸控制返回給操作系統)。恢復執行在調用函數
在點後立即致電


(40)short
聲明短整型變量或函數.

(41)signed,unsigned
聲明有符號類型變量或函數;聲明無符號類型變量或函數.

(42)static
聲明靜態變量.When modifying a variable, the static keyword specifies that the variable has

static durationinitializes it to 0 unless another value is specified.
當修改一個變量,static關鍵字指定的變量
靜態durationinitializes爲0,除非另一個指定值

(43)struct
聲明結構體變量或函數.struct 類型是一種值類型,通常用來封裝小型相關變量組.
struct hello文件名

(44)switch

Allows selection among multiple sections of code, depending on the value of an integral

expression.
允許選擇多個之間的代碼段,這取決於一個整體的價值
表達


(45)template
模板.The template declaration specifies a set of parameterized classes or functions. 
該模板聲明指定的類或函數的參數化設置

(46)this
The this pointer is a pointer accessible only within the nonstatic member functions of a

class,struct, or union type. 
在該指針是一個指針訪問只有在一個非靜態成員函數
類,結構或聯合類型

(47)typedef
用以給數據類型取別名.Introduces a name that, within its scope, becomes a synonym for the

type given by the type-declaration portion of the declaration.
引入了一個名稱,在其範圍內,成爲一個同義詞
該類型聲明宣言的一部分給定類型

(48)typeid
typeid is used to get the Type for a type at compile time.
typeid用於獲取一個類型的類型在編譯時

(49)typename
Tells the compiler that an unknown identifier is a type.Use this keyword only in template

definitions.
告訴編譯器是一個未知的標識符是一個type.Use這只是在模板中的關鍵字
定義

(50)union
聲明聯合數據類型.A union is a user-defined data or class type that, at any given time,

contains only one object from its list of members (although that object can be an array or a

class type).
阿聯盟是一個用戶定義的數據類型或類,在任何特定時間,
只包含其成員名單的對象(雖然這個對象可以是一個數組或
類類型)


(51)using
The using declaration introduces a name into the declarative region in which the

usingdeclaration appears.
使用聲明的聲明中引入了在該地區出現一個名稱usingdeclaration

(52)virtual

聲明虛基類或虛函數.The virtual keyword declares a virtual function or a virtual base class.
virtual關鍵字聲明瞭一個虛函數或虛基類


(53)void
聲明函數無返回值或無參數,聲明無類型指針.

When used as a function return type, the void keyword specifies that the function does not

return a value. When used for a function's parameter list, void specifies that the function

takes no parameters. When used in the declaration of a pointer, void specifies that the

pointer is "universal."

(54)volatile 
說明變量在程序執行中可被隱含地改變,表明某個變量的值可能在外部被改變,優化器在用到這個變量時

必須每次都小心地重新讀取這個變量的值,而不是使用保存在寄存器裏的備份。Thevolatile keyword is

a type qualifier used to declare that an object can be modified in the program by something

such as the operating system, the hardware, or a concurrently executing thread.
Thevolatile關鍵字
一個類型限定符用來聲明一個對象可以在程序中修改的東西
如操作系統,硬件或併發執行線程。


(55)wchar_t
寬字.

(56)while
循環語句的循環條件

(57)class

轉自:http://hi.baidu.com/08172028/blog/item/0780f4045347d38ae850cde4.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章