/*
字符数组和字符串:
1.
字符数组定义:
char arr[长度] 最后一位是'\0',字符数组结束
2.
获取字符数组长度:strlen(数组名)
for(int i = 0;i<strlen(arr);i++){
cout<<arr[i]<<" ";
}
3.
识别最后一位'\0'
for(int i = 0;arr[i]!='\0';i++){
cout<<arr[i]<<" ";
}
4.
获取整行字符数组:
cin.getline(数组名,长度)
5.
字符数组常见函数:
strcpy(目标数组,原数组) 字符数组拷贝
strcat(str1,str2) 两个字符数组连接(str1后面添加str2)
strchr(str,‘a’)在字符数组中查找子串,找到1,没找到0
判断单个字符通用方法:
isupper(ch) 判断ch是否为大写
isupper(ch) 判断ch是否为小写
isupper(ch) 判断ch是否为数字
isalpha(ch) 判断ch是否为大字母
6.
字符串定义:
string a;
输入没有空格
cin>>a;
输入有空格(整行)
getline(cin,str)
7.
字符串常见函数:
str.size()或str.strlength() 获取字符串长度:
str.empty() 判断字符串是否为空:
str.clear() 清空字符串
str.find("sub") 查找字符串中是否存在子串sub
str.insert(位置,“内容”) 字符串插入
str.eraser(位置,删除长度) 字符串删除
str.replace(位置,长度,“替换内容”)字符串替换
/*
8.
结构体:可以存储多种数据元素
struct {
数据类型1;
数据类型2;
..........
};
// 引用结构体
1.student stu;//创建stu对象
2.struct 数据体名{
数据类型1;
数据类型2;
..........
}stu; //结构体后面创建stu对象
// 结构体填充数据
cin>>stu.数据类型
//结构体初始化
结构体名 对象名 ={"xx",成绩,成绩}
a.name="xx";
a.max=成绩
..
// 结构体数组
1.在结构体结束后面直接加数组
struct 结构体{
数据...
}a[100];
2. 结构体名 数组名[空间]
*/
struct student{
string name; //姓名
int math;//数学成绩
int chinese;//语文成绩
int total;//总分
}a,b,c; //创建三名学生
int main()
{
cin>>a.name>>a.math>>a.chinese; //输入数据
a.total=a.math+a.chinese;
cout<<a.name<<"总成绩为:"<<a.total<<endl;
cin>>b.name>>b.math>>b.chinese; //输入数据
b.total=b.math+b.chinese;
cout<<b.name<<"总成绩为:"<<b.total<<endl;
cin>>c.name>>c.math>>c.chinese; //输入数据
c.total=c.math+c.chinese;
cout<<c.name<<"总成绩为:"<<c.total<<endl;
}
*/
#include <bits/stdc++.h>
using namespace std;
char arr[100];
char arr1[100];
int main()
{
cin.getline(arr,100);
for(int i=0;i<strlen(arr);i++){
cout<<arr[i]<<" ";
}
return 0;
}