我正在尝试创建一个随机数组,然后按升序对其进行排序。但是当我输入3或更高的数字来向数组添加数字时,它会在数组填充并输出到窗口后崩溃,并尝试开始对其进行排序。我似乎无法弄清楚为什么会发生这种情况......
#include "stdafx.h"
#include <iostream>
#include <algorithm>
#include <random>
#include <ctime>
using namespace System;
int main(array<System::String ^> ^args)
{
int size, i;
int *array;
array = new int[size];
srand(time(NULL));
Console::WriteLine("Input amount of numbers you'd like in the array: ");
String^ str = Console::ReadLine();
size = System::Convert::ToInt32(str);
for (i = 0; i < size; i++) {
array[i] = rand();
}
for (i = 0; i < size; i++) {
Console::Write(array[i] + ", ");
}
Console::WriteLine("\n\n");
std::sort(array, array + size);
for (i = 0; i < size; i++) {
Console::Write(array[i] + ", ");
}
}