1.cout 输出函数,存在于c++中iostream的文件中。
(cout 可用于字符串和数字)
2.控制符 endl 表示:重起一行。
3.cin输入函数。
#include <iostream>
int main()
{
using namespace std;//访问位于名称空间std中的cout定义。
int a;
cin >> a;
cout << "a:";
cout << a<<endl;
return 0;
}
4.变量必须要声明。
5.类的简介
类就是用户定义的一种数据类型。
类描述指定了可对类对象执行的所有操作。
6.c++不允许将函数定义嵌套在另一个函数定义中。每个函数定义都是独立的,所有函数的创建都是平等的。
练习题:
#include <iostream>
using namespace std;
void shu();
void shu2();
int main()
{
int i;
for(i=0;i<2;i++)
{
shu();
}
for (i = 0; i < 2; i++)
{
shu2();
}
return 0;
}
void shu()
{
cout << "Three blind mice!"<<endl;
}
void shu2()
{
cout << "See how they run"<<endl;
}
#include <iostream>
using namespace std;
int main()
{
int age,month;
cout << "Enter_your age:";
cin >> age;
month = age * 12;
cout << month<<endl;
return 0;
}
#include <iostream>
using namespace std;
void shu(int, int);
int main()
{
int min, hour;
cout << "输入小时数:";
cin >> min;
cout << "输入分钟数:";
cin >> hour;
shu(min, hour);
return 0;
}
void shu(int min, int hour)
{
cout << "Enter the number of hours:"<<min<<endl;
cout << "Enter the number of minutes:" << hour << endl;
cout << "Time:" << min << ":" << hour << endl;
}