C++全称:C Plus Plus (.cpp)
在C基础上扩充了:类与对象、多继承、命名空间、运算符重载、虚函数、异常处理、模版、、、
程序执行效率高,很多语言的底层都是用C、C ++实现的
iostream :C++的输入输出库,类似于C的 stdio.h
cin :istream类型的对象 ; cout :ostream类型的对象。还有cerr 和clog 两个ostream类型的对象
endl:end line 换行
/* 命名空间的概念(usingnamespace std)
:: 作用域操作符
*/
#include <iostream>
using namespace std; //提前使用命名空间
int main(int argc, const char * argv[]) {
std::cout << "Hello World!" << std::endl; //未提前使用命名空间时
int num;
// scanf("%d",&num);
// printf("it's %d\n",num * 10);
cin >> num ;
cout << "it's " << num * 10 << endl;
int age = 18;
double height = 1.8;
char name[12] = "huang";
// printf(" My name is %s , age is %d , height is %f\n",name,age,height);
cout << "My name is " << name << ", age is " << age << ", height is " << height << endl;
/* endl 全称 end line */
return 0;
}
结构体:可以增加成员函数
struct Student{
int age; //成员变量
int num;
char name[12];
//成员函数
void study(int a){
cout << name << " age is " << age << " num is " << num << " , a is " << a << endl;
}
};
int main(int argc, const char * argv[]) {
Student s = {18,101,"Mack"};
s.study(12);