在大一下學期學習了c語言,最近又想學一下c++,想提高一下編程功底,在此記錄一下在有c基礎(及其拙劣)的情況下,自己的編程進階之路。
sizeof()
返回字節的大小
short a=10;
cout << sizeof(short)<< endl;//2
cout << sizeof(a) << endl;//2
cout << sizeof(int) << endl;//4
針對不同的操作系統,返回的值不同。
在float後面加 f
float a = 1.20f;
double b = 1.222;
創建字符型變量,用單引號,且只能一個字母;
char ch = 'a';
查找ASCII碼:
A----65
a-----97
char ch = 'a';
cout << (int)ch<< endl;
製表符 \t 有對齊的作用
cout << "aaaa\thello"<< endl;
cout << "aa\thello" << endl;
cout << "aaaaaa\thello" << endl;
輸出:
char str[] = "hello world";//c風格字符串
cout << str << endl;
string str2 = "hello c++"; //c++風格,
#include<string>
cout << str2 << endl;
邏輯與
&&
邏輯或
||
選擇結構:
if()
{}
esle if()
{}
else
{}