【发布时间】:2016-06-25 23:37:51
【问题描述】:
我有错误,突出显示“cout
#include <iostream>
#include <string>
#include <sstream>
using namespace std;
int main()
{
int numbers[SIZE] = { 6,3,1,9,4,12,17,2 };
for (int i = 0; i < 8; i++)
{
cout << array[i] << endl;
}
system("pause");
}
const int SIZE = 8;
void insertionSort(int numbers[], int arraySize)
{
int i, j, insert;
for (i = 1; i < arraySize; i++)
{
insert = numbers[i];
j = i;
while ((j > 0) && (numbers[j - 1] > insert))
{
numbers[j] = numbers[j - 1];
j = j - 1;
}
numbers[j] = insert;
}
}
【问题讨论】:
-
尝试
cout << numbers[i] << endl;和SIZE应该在main之前定义。 -
@knivil 谢谢你的工作
-
还要注意
std::array是标准库中的一个类,通过using namespace std;你已经把它扔到了全局范围内,这使得当你潜在地意味着其他东西时使用标识符array一个错误。 -
@knivil 当我运行程序时数组没有排序,有什么建议吗?
标签: c++ arrays function sorting insertion