#include <iostream>
using namespace std;
#include <string>// 用string字符串时需要
/*常量定义 #define 宏常量名字 数据 */
#define Day 7 //Day = 7
int main()
{
//变量创建 数据类型 变量名 = 变量初始值
int a = 10;
cout << "a=" << a << endl;
cout << "hello world" << endl;
cout<<"一周多少天:"<<Day<<"天"<<endl;
//常量定义 const 修饰变量
const int month = 12;//定义之后也是常量
cout<<"A year 有"<<month<<"个月"<<endl;
short nmu1 = 10;//短整型
int num2 = 10;//整型
long num3 = 10;//长整型
long long num4 = 10;//长长
// sizeof(数据类型/变量名) 就可得到占用内存为多大
cout << "占用内存空间是" << sizeof(int) << endl;
/*实型(浮点型、小数)
单精度 float 7位有效
双精度 double 15-16位有效*/
float f1=3.14f;
double f2=3.14;
//输出小数时默认位6位有效数字
//科学计数法
float f3=3e2;//3 * 10^2
cout<<"f3= "<<f3<<endl;
float f4 = 3e-2;//3 * 10^(-2)
cout << "f4= " << f4 << endl;
//字符型
char ch = 'a';//只能存一个字符 'abcde'不正确
cout << "a= " << ch << endl;
char ch1 = 'abcd';
cout << "abcd= " << ch1 << endl;//只显示 d
//字符型变量对应的ASCII编码
cout << (int)ch << endl;
// a - 97
// A - 65
//转义字符
// \n 换行 与 结尾的 <<endl 作用相同
cout << "\\\n";// 显示一个\需要两个\\来表示
// \t 水平制表符 == 空格 看着整齐
cout << "aaa\t hello world " << endl;
cout << "aaaaa\t hello world " << endl;
cout << "aa\t hello world " << endl;
//字符串型
string name = "姓名";//需要一个头文件,见第三行
cout << name << endl;
//布尔类型 输出0或者1 只要是非0的都代表真
bool flag = true;//ture=1 真
cout << flag << endl;
flag = false;//flase=0 假
cout << flag << endl;
// 数据输入 从键盘得到输入
int a1=0;
cout<<"赋值操作"<<
system("pause");
return 0;
}
//注释 单行//
// 多行/* */
//main()只有一个,源文件中多个函数要调用,则需要命名不同main main1 main2....
C++学习路程 22/3/3 PM 20:00
于 2022-03-03 22:07:36 首次发布