学习C++第1天

1.C++头文件#include<iostream>
2.输出格式std::cout<<"hello world!";
这个格式必须在每一次输出时使用std::cout不建议使用
原因在于相当于一个全局变量被定义成了局部变量去使用,非常麻烦,容易出错
3.若是定义一个名字空间就可以按下面格式输出,常用!!
using namespace std;//定义名字空间
输出格式
cout<<hello world!<<endl;//输出格式
4.第一个C++程序

#include<iostream>
int main(){
	std::cout<<"hello world!";
	return 0;
}

5.函数声明和继承

//声明
class C1//类名为C1
{
public:
	void f1();//函数f1
};
class C2:public C1//类C2,继承C1
{
public:
		void f2();//函数f2
};
int main(){		//主函数
	C2 a;//a是对象,其类型是C2
	a.f2();//通过对象调用函数
	return 0;
}
//类的定义
void C1::f1()
{
	
}
void C2::f2()
{
	
}

猜你喜欢

转载自blog.csdn.net/qq_41935906/article/details/82750318
今日推荐