#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
struct tiaodu
{
int id; //作业编号
int time; //作业时间
};
bool cmp(tiaodu& s1, tiaodu& s2)
{
return s1.time < s2.time;
}
int main()
{
int n; //作业的数量
cout << "请输入作业的数量" << endl;
cin >> n;
const int c = n;
tiaodu td[5];
}
像这里,我想在 tiaodu td[] 里面填上n,想自由定义结构体的长度,该如何填呢,
直接 填 tiaodu td[n]; 不行嘛?
我这没问题
那你就这样
tiaodu * td = new tiaodu[n];
const int c = n;
这里n是输入的变量,不能用于c的值
c的值要是一个数字,由编译器直接确定的
你这里vc++不能支持变量作为数组大小,你的思路不成立。
你只能是定义一个很大的数组,但是只用前面一部分
或者是malloc动态分配
new 一下试试