1c+输入输出头文件
.#include <iostream>
#include <iostream>
using namespace std;
int main()
{
cout<<"hello world!"<<endl;
return 0;
}
-----------------------
2.数据类型
int number = 1;
char character='a';
bool blloean=true;//or false
char* aaa="hello";
string cppstring="world";
3。输出
cout<<number<<endl;//1
cout<<character<<endl;//a
cout<<boolean<<endl;//1
cout<<cstring<<endl;//hello
cout<<cppstring<<endl;//world;
4.输入
(1)终端输入单个元素;
int a;
cin>>a
;
(2)终端输入一行
<1>getline(cin, b);//将输入的一行都读到字符串b里(不用写长度)
<2>char str[100];
cin.getline(str,100);//第一个参数是个字符指针
5.c++语法类型--bool
bool yes=true;
if(yes){
puts("yes")
}
else{
puts("no");
}
6.c++----动态开辟内存
int* number=new int;
int* arr=new int[100];
int* carr =(int*)malloc(100*sizeof(int));
7.函数重载
定义:两个函数可以名字相同,但参数列表和返回值不同;
int add(int a,int b){
return a+b;
}
int add(int a){
return a;
}
int add(int a,int b=0){ //这里b=0代表如果b没有赋值,默认为0,赋值了按赋值的算
return a+b;
}
8.结构体声明
struct node{
int number;
note* next;
};
node* head;
9.遍历的概念
比如:一堆盒子中,其中有些盒子里有糖,要知道总共有多少糖,我们要打开每个盒子去看一下,这就是遍历。