C Bjarne Stroustrup C GNU GCC C Standard
C++ 創始人 Bjarne Stroustrup
C++ 標準與產品 標準 編譯器實作(產品) GNU GCC C++ Standard 1998. 6 ANSI/ISO Borland C++/ C++ Builder Microsoft Visual C++ (. Net) 其他
The First Program // 前置處理器先處理宣告 #include <iostream> #include <stdlib. h> #include <cstdlib> /* 另一種註解方式,可以一次註解一個區塊 就像這樣子 */ using namespace std; 宣告將使用 C++ 標準程式庫的函式 // 程式的起始點 int main(int argc, char *argv[]) { cout << "Hello C++!" << endl; system("PAUSE"); return 0; } 每行命令結尾都需要「 ; 」
常見的變數型態 n 整數 q n 浮點數 q n float, double 字元 q n int, long char 布林 q bool
C++ 的 string 型別 n 宣告方式 string s 1(“Hello C++!”); string s 2 = “Yes, you can do this”; string s 3; s 3 = s 1; // now we can do this n n string 型別提供有一些成員方法 提取個別元素的方式 s 1[4] = ‘o’;
整數的表示範圍 int 若配置 4 Bytes 的空間儲存 可儲存範圍 -231 ~ 231 -1 1 Byte = 8 bits n 最大可表示之數 231 = 10 n log 231 = log 10 n n= 31 * log 2 = 31 * 0. 3010 = 9. 331 大約是 1010 以下, 2147483647
- Slides: 23