建立一个结构体数组,数组长度为待输入的n(常数),这个n怎么定义?
我是这么写的,但报错说n计算结果不是常数#include<iostream>usingnamespacestd;structstudent{intnumber;intna...
我是这么写的,但报错说n计算结果不是常数
#include<iostream>
using namespace std;
struct student
{
int number;
int name[20];
int project1;
int project2;
int project3;
int project4;
int project5;
int grade;
};
int main()
{
int n;
cin >> n;
struct student a[n];
return 0; 展开
#include<iostream>
using namespace std;
struct student
{
int number;
int name[20];
int project1;
int project2;
int project3;
int project4;
int project5;
int grade;
};
int main()
{
int n;
cin >> n;
struct student a[n];
return 0; 展开
展开全部
数组的长度不能是变量,只能是常量表达式
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
#include<iostream>
using namespace std;
struct student
{
int number;
int name[20];
int project1;
int project2;
int project3;
int project4;
int project5;
int grade;
};
int main()
{
int n;
cin >> n;
struct student *p;
student *p=new student[n];
delete *p;
return 0;
}
追问
还是报错
student *p重定义{19行}
“delet”无法从“student”转化为“void”{21行}
追答
失误,手写错误。
#include <iostream>
using namespace std;
struct student
{
int number;
int name[20];
int project1;
int project2;
int project3;
int project4;
int project5;
int grade;
};
int main()
{
int n;
cin >> n;
student *p=new student[n];
delete []p;
return 0;
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
cin >> n;
struct student a[n];
cin >>n;
struct student *p;
p = malloc(sizeof(student) * n);
struct student a[n];
cin >>n;
struct student *p;
p = malloc(sizeof(student) * n);
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询