Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++;处理';结构';和弦 我在C++代码中有一个问题,我想在每个日期加上n个学生,但是当我和IF比较时,我有一个错误,这里是我的代码 #include <iostream> #include <stdio.h> #include <string.h> struct Address { char city[20]; char street[20]; }; struct University { char name1[20],name2[20],name3[20]; }; struct student { char name[20]; char degree[20]; University un; Address add; }; using namespace std; int main (){ student st[20]; int n,i,j; do{cin>>n;}while(n<=0 || n>20); for(i=0;i<n;i++) { cout<<" Name Of student "<<i+1<<"\n"; cin>>st[i].name; cout<<" Degree Of student "<<i+1<<"\n"; cin>>st[i].degree; cout<<" University 1 \n"; cin>>st[i].un.name1; cout<<" University 2 \n"; cin>>st[i].un.name2; cout<<" University 3 \n"; cin>>st[i].un.name3; cout<<" Enter The City Of student "<<i+1<<"\n"; cin>>st[i].add.city; cout<<" Enter The Street Of student "<<i+1<<"\n"; cin>>st[i].add.street; cout<<"\n* * * * * * * * * * * * * * * * * * * *\n"; } for(i=0;i<n;i++) if(st[i].degree == "phD") cout<<st[i].name<<" is OK"; cout<<endl; return 0; } #包括 #包括 #包括 结构地址 { 查尔城[20]; 查尔街[20]; }; 结构大学 { 字符名称1[20],名称2[20],名称3[20]; }; 结构学生 { 字符名[20]; 焦度[20]; 联合国大学; 地址添加; }; 使用名称空间std; int main(){ student st[20]; int n,i,j; do{cin>>n;}while(n20); 对于(i=0;i_C++_Struct - Fatal编程技术网 >n;}while(n20); 对于(i=0;i,c++,struct,C++,Struct" /> >n;}while(n20); 对于(i=0;i,c++,struct,C++,Struct" />

C++;处理';结构';和弦 我在C++代码中有一个问题,我想在每个日期加上n个学生,但是当我和IF比较时,我有一个错误,这里是我的代码 #include <iostream> #include <stdio.h> #include <string.h> struct Address { char city[20]; char street[20]; }; struct University { char name1[20],name2[20],name3[20]; }; struct student { char name[20]; char degree[20]; University un; Address add; }; using namespace std; int main (){ student st[20]; int n,i,j; do{cin>>n;}while(n<=0 || n>20); for(i=0;i<n;i++) { cout<<" Name Of student "<<i+1<<"\n"; cin>>st[i].name; cout<<" Degree Of student "<<i+1<<"\n"; cin>>st[i].degree; cout<<" University 1 \n"; cin>>st[i].un.name1; cout<<" University 2 \n"; cin>>st[i].un.name2; cout<<" University 3 \n"; cin>>st[i].un.name3; cout<<" Enter The City Of student "<<i+1<<"\n"; cin>>st[i].add.city; cout<<" Enter The Street Of student "<<i+1<<"\n"; cin>>st[i].add.street; cout<<"\n* * * * * * * * * * * * * * * * * * * *\n"; } for(i=0;i<n;i++) if(st[i].degree == "phD") cout<<st[i].name<<" is OK"; cout<<endl; return 0; } #包括 #包括 #包括 结构地址 { 查尔城[20]; 查尔街[20]; }; 结构大学 { 字符名称1[20],名称2[20],名称3[20]; }; 结构学生 { 字符名[20]; 焦度[20]; 联合国大学; 地址添加; }; 使用名称空间std; int main(){ student st[20]; int n,i,j; do{cin>>n;}while(n20); 对于(i=0;i

C++;处理';结构';和弦 我在C++代码中有一个问题,我想在每个日期加上n个学生,但是当我和IF比较时,我有一个错误,这里是我的代码 #include <iostream> #include <stdio.h> #include <string.h> struct Address { char city[20]; char street[20]; }; struct University { char name1[20],name2[20],name3[20]; }; struct student { char name[20]; char degree[20]; University un; Address add; }; using namespace std; int main (){ student st[20]; int n,i,j; do{cin>>n;}while(n<=0 || n>20); for(i=0;i<n;i++) { cout<<" Name Of student "<<i+1<<"\n"; cin>>st[i].name; cout<<" Degree Of student "<<i+1<<"\n"; cin>>st[i].degree; cout<<" University 1 \n"; cin>>st[i].un.name1; cout<<" University 2 \n"; cin>>st[i].un.name2; cout<<" University 3 \n"; cin>>st[i].un.name3; cout<<" Enter The City Of student "<<i+1<<"\n"; cin>>st[i].add.city; cout<<" Enter The Street Of student "<<i+1<<"\n"; cin>>st[i].add.street; cout<<"\n* * * * * * * * * * * * * * * * * * * *\n"; } for(i=0;i<n;i++) if(st[i].degree == "phD") cout<<st[i].name<<" is OK"; cout<<endl; return 0; } #包括 #包括 #包括 结构地址 { 查尔城[20]; 查尔街[20]; }; 结构大学 { 字符名称1[20],名称2[20],名称3[20]; }; 结构学生 { 字符名[20]; 焦度[20]; 联合国大学; 地址添加; }; 使用名称空间std; int main(){ student st[20]; int n,i,j; do{cin>>n;}while(n20); 对于(i=0;i,c++,struct,C++,Struct,使用strcmp()比较char字符串 比如: 那么,for for循环将保持相同的,例如“代码> char城市(20);,您应该考虑 STD::String 类型。它提供了您在比较中使用的相等运算符(=< /代码>)和其他一些功能。谢谢,但是我应该使用函数吗?如果没有函数0终止的字符字符串,我就不能使用。除非你有特定的理由重新发明轮子(又名学校):是的,使用标准函数。@user3457718这是string.h中的标准函数如果您想在结构中使用string,请参考@user3457718。我在上

使用
strcmp
()比较
char
字符串

比如:


那么,for for循环将保持相同的

,例如“代码> char城市(20);,您应该考虑<代码> STD::String 类型。它提供了您在比较中使用的相等运算符(<代码>=< /代码>)和其他一些功能。

谢谢,但是我应该使用函数吗?如果没有函数0终止的字符字符串,我就不能使用。除非你有特定的理由重新发明轮子(又名学校):是的,使用标准函数。@user3457718这是
string.h中的标准函数
如果您想在结构中使用string,请参考@user3457718。我在上面编辑了我的答案
for(i=0;i<n;i++)
        if(strcmp(st[i].degree,"phD") == 0)
        cout<<st[i].name<<"  is  OK";
struct student 
{   
char name[20];
string degree;
University un;
Address add;
};