#include <iostream> #include <string> using namespace std; //单行 注释 /*多行注释*/ //常量定义 #define Month 12; #define Day 31; /*main为c++的入口函数*/ int main() { //变量定义 char b = 'B'; int a = 10; const int hours = 24; const bool flags = true; cout << "hello world " << endl; cout << "a = " << a << endl; cout << "b = " << b << endl; cout << " "; cout << " "; cout << " "; cout << " "; cout << " "; cout << " "; float second = 60.0009f; // 单精度浮点 cout << "年份 ="<< Day; cout << "月份 =" << Month; cout << "小时 =" << hours; cout << " "; cout << "one minute has " <<second << " s"; cout << " "; cout << ""; cout << ""; int Times = hours * Month; cout << "Month * Hours ==" << Times; cout << " "; cout << " "; cout << " "; cout << " "; cout << " "; //sizeof关键字:统计字节数 cout << "short占空间:" << sizeof(short); cout << "int占空间:" << sizeof(int); cout << "long占空间:" << sizeof(long); cout << "long long 占空间:" << sizeof(long long); cout << "Month 占空间:" << sizeof Month; cout << "second占空间:" << sizeof second; cout << "char 占空间:" << sizeof(char); cout << " "; cout << " "; cout << " "; //字符型 char ch = 'a'; //只能有一个变量,单引号 cout << ch << endl; cout << sizeof ch << endl; cout << int(ch) << endl; //字符串转换为ASCII码值 //字符串型 char s1[] = "this is that ";//C >字符数组,双引号 string s2 = "this is not";//C++ >字符数组,双引号。头文件标识#include <string> cout << s1 << endl; cout << s2 << endl; //布尔类型 bool flag = true; bool unflag = false; cout << flag << endl; //0 cout << unflag << endl; //1 cout << sizeof flag << endl; /* //cin 数据输入:从键盘获取输入 int mya = 0; cout <<"How old are u ? " << endl; cin >> mya; cout << "U are " << mya<<" years old "<<endl; string talk = ""; cout << "What did u say?" << endl; cin >> talk; cout << "U said :" << talk << endl; cout << " " << endl; cout << " " << endl; cout << " " << endl; */ //运算符 int a1 = 10; int a2 = 20; int a1_a2 = a1 + a2; cout << a1_a2 << endl; //递增运算符 int a1 = 30; a1++; cout << a << endl; system("pause"); return 0;