#include<iostream>
#include<cstring>//cstring头文件
using namespace std;
int main()
{
//----------------------1.0 字符数组----------------------------
//初始化 方法1
//char dog[8]={'a','b','c','d','e','f','g','h'};
//char cat[8]={'a','b','c','d','e','f','g','\0'};
////法2初始化
//char dog_B[8]="yanggan";
//char cat_B[8]="justtes";//输入不能超过7个,第8位默认为 ‘\0’
//for(int i=0;i<8;i++)
//{
//cout<<dog_B[i];
//}
//----------------------2.0字符数组中 使用字符串----------------------------
const int Size =15;
char name1[Size];
char name2[Size]="c++cowboy";
cout<<"hello,i am "<<name2<<"!,what is your name?"<<endl;
cin>>name1;
//sizeof()计算数字长度,而strlen()计算数组中字符串的长度。
cout<<"well,"<<name1<<",you name has "<<strlen(name1)<<" letter.\n";//计算字符长度
cout<<"And is stored in an array of "<<sizeof(name1)<<" bytes."<<endl;//计算数组长度
name2[3]='\0';//用 '\0'替换掉字符数组中第三个,然后输出时候读取到'\0'就停止了
cout<<"Here are the first 3 characters of my name : "<<name2<<endl;
}