在大一下学期学习了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
{}