cpp--data type
Posted blue-moniter4
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了cpp--data type相关的知识,希望对你有一定的参考价值。
cpp允许用户根据自己声明一些类型【数组,结构体类型,共用体类型,枚举类型,类类型】user-defined type
1 #include <iostream> 2 using namespace std; 3 4 struct Data 5 { 6 int month; 7 int day; 8 int year; 9 }; 10 struct Student 11 { 12 int num; 13 char name[20]; 14 char sex; 15 Data birthday; 16 float score; 17 }student1,student2={10002,"hello",‘b‘,5,23,9000,90}; 18 int main() 19 { 20 student1=student2; 21 cout<<"student1 info about:"<<endl; 22 cout<<"num:"<<student1.num<<endl; 23 cout<<"name:"<<student1.name<<endl; 24 cout<<"sex:"<<student1.sex<<endl; 25 cout<<"month:"<<student1.birthday.month<<endl; 26 cout<<"year:"<<student1.birthday.year<<endl; 27 cout<<"score:"<<student1.score<<endl; 28 }
结构体数组:每个数组元素都是一个结构体类型的数据,他们都分别包括各个成员项
1 #if 0 2 3个候选人,最终有一个人当选,10个人参与投票,键盘输入3个候选人名字(10次),输出每个候选人的得票结果 3 #endif 4 5 #include <iostream> 6 using namespace std; 7 8 struct Person//声明结构体类型Person 9 { 10 char name[20]; 11 int cout; 12 }leader[3]={"a",0,"b",0,"c",0};//定义Person类型的数组leader 13 int main() 14 { 15 int i,j; 16 string leader_name;//字符变量 17 for(i=0;i<10;i++) 18 { 19 cin>>leader_name; 20 for(j=0;j<3;j++) 21 if(leader_name==leader[j].name)//将输入的名字与候选人名字作对比 22 leader[j].cout++;//相同,计数+1 23 } 24 cout<<endl; 25 for(i=0;i<3;i++) 26 cout<<leader[i].name<<":"<<leader[i].cout<<endl; 27 return 0; 28 29 }
以上是关于cpp--data type的主要内容,如果未能解决你的问题,请参考以下文章
SpringBoot启动报错“Consider defining a bean of type ‘xxx.mapper.UserMapper‘ in your configuration.“(代码片段
detectron2报AttributeError: Attribute ‘evaluator_type‘ does not exist in the metadata of dataset(代码片段
Operator '||' cannot be applied to operands of type 'bool?' and 'bool?'(代码片段
Operator '||' cannot be applied to operands of type 'bool?' and 'bool?'(代码片段
SpringBoot中表单提交报错“Content type ‘application/x-www-form-urlencoded;charset=UTF-8‘ not supported“(代码片段
解决spring-boot启动中碰到的问题:Cannot determine embedded database driver class for database type NONE(转)(代码片段