日期 | 講師 | 內容 |
---|---|---|
7/4 | 227 陳泓宇 | 資讀介紹 C++ 編輯器安裝 C++ 語法 (輸入輸出 變數 運算子) |
7/19 | 225 陳澔樂 | 競賽介紹 OJ 介紹 語法 (條件 迴圈 陣列 時間複雜度) |
8/09 | 227 張秉中 | 函數 struct & object 運算子重載 指標 參考 |
8/23 | 227 張庭瑋 | stack queue heap STL |
8/24 | 227 陳柏凱 | 基本演算法介紹 ( 排序 枚舉 greedy 二分搜 ) |
執行速度快,編寫程式較困難且程式碼不易理解。
接近人類日常生活用語,簡單易懂,在高階語言中,一個命令就可以代表數個組合語言中的命令。
切記一定要按確定而不是直接關掉
一鍵編譯&執行C++
#include <iostream>
using namespace std;
int main(){
cout << "Hello World";
return 0;
}
#include <iostream>
using namespace std;
int main(){
int a; //定義變數名稱為a 型別為int
a = 5; //把a的值變成5
}
名稱 | 使用空間 bytes |
值域 |
---|---|---|
short | 2 | -32768~32767 |
int | 4 | -2147483648~2147483647 |
unsigned int | 4 | 0~4294967295 |
long long | 8 | -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 |
unsigned long long | 8 | 0~18,446,744,073,709,551,615 |
名稱 | 使用空間 bytes |
值域 | 有效位數 |
---|---|---|---|
float | 4 | ±3.4× \(10^{-38}\) ~ ±3.4× \(10^{38}\) |
7 |
double | 8 | ±1.7× \(10^{-308}\) ~ ±1.7× \(10^{308}\) |
15 |
long double | 8 | ±1.7× \(10^{-308}\) ~ ±1.7× \(10^{308}\) |
15 |
#include <iostream>
using namespace std;
int main(){
int n;
n = 99;
string s;
s = "Hello World";
char c;
c = 'h';
float f;
f = 1.65464;
bool b;
b = true;
}
#include <iostream>
using namespace std;
int main(){
int age;
int years;
string name;
string school;
bool gender;
}
#include <iostream>
using namespace std;
int main(){
int n;
int nn;
int nnn;
string s;
string ss;
string sss;
bool b;
bool bb;
}
#include <iostream>
using namespace std;
int main(){
string a;
cin >> a; //讀到空白或換行
char b;
cin.get(b); //一次讀一個字元
string c;
cin.getline(c); //讀到換行
}
#include <iostream>
using namespace std;
int main(){
cout << "Hello World"; //輸出 Hello World
cout << endl; //換行
cout << '\n'; //換行
cout.flush(); //清空緩衝區
}
#include <iostream>
#include <iomanip>
using namespace std;
int main(){
float f;
f = 1.666523;
cout << fixed << setprecision(5) << f; //1.66652
}
#include <iostream>
using namespace std;
int main(){
int a;
a = 3; //把a的值設為3
string s;
s = "abcd"; //把s的值設為abcd
}
#include <iostream>
using namespace std;
int main(){
int a = 5;
a = a + 2; //把a設為a+2
cout << a; //7
int b = 5;
b = b - 2;
cout << b; //3
int c = 5;
c = c * 2;
cout << c; //10
int d = 5;
d = d / 2;
cout << d; //2
int e = 5;
e = e % 2; //e除以二的餘數
cout << e; //1
}
#include <iostream>
using namespace std;
int main(){
int a = 5;
a += 2; //把a設為a+2
cout << a; //7
int b = 5;
b -= 2;
cout << b; //3
int c = 5;
c *= 2;
cout << c; //10
int d = 5;
d /= 2;
cout << d; //2
int e = 5;
e %= 2;
cout << e; //1
}
#include <iostream>
using namespace std;
int main(){
int a = 5;
a++; //a變成a+1
cout << a; //6
int b=5;
b--;
cout << b; //4
}
#include <iostream>
using namespace std;
int main(){
bool a;
a = (5 > 3);
cout << a; //true
bool b;
b = (5 == 3);
cout << b; //false
bool c;
c = (5 != 3);
cout << c; //true
}
#include <iostream>
using namespace std;
int main(){
bool a;
a = (true && true);
cout << a; //true
bool b;
b = (false || true);
cout << b; //true
bool c;
c = (! false);
cout << c; //true
}
#include <iostream>
using namespace std;
int main(){
int a = 1; //00000000000000000000000000000001
a = a << 2; //00000000000000000000000000000100
cout << a; //4
int b = 7; //00000000000000000000000000000111
b >> 2; //00000000000000000000000000000001
cout << b; //1
int c = 3; //00000000000000000000000000000011
int d = 6; //00000000000000000000000000000110
int e = c&d; //00000000000000000000000000000010
int f = 3; //00000000000000000000000000000011
int g = 6; //00000000000000000000000000000110
int h = f|g; //00000000000000000000000000000111
int i = 3; //00000000000000000000000000000011
int j = 6; //00000000000000000000000000000110
int k = i^j; //00000000000000000000000000000101
int l = 3; //00000000000000000000000000000011
int m = ~l; //11111111111111111111111111111100
cout << m; //-4
}
Primary | Alternative |
---|---|
&& | and |
&= | and_eq |
& | bitand |
| | bitor |
~ | compl |
! | not |
!= | not_eq |
|| | or |
|= | or_eq |
^ | xor |