我正在尝试从文件中读取数字列表并通过将它们读入数组然后对数组的内容进行排序来对它们进行排序。但我越来越
error:incompatible types in assignment of 'std::basic_ostream<char, std::char_traits<char> >' to 'int [1]'
我对编程相当陌生,这是我第一次使用 C++ 谁能告诉我如何将数字列表写入数组以便我可以对它们进行排序?这是我所拥有的:
#include <fstream>
#include <iostream>
#include <iomanip>
#define ANYSIZE_ARRAY 1
using std::cout;
using std::endl;
int main()
{
const char* filename = "test.txt";
std::ifstream inputFile(filename);
int numbers[ANYSIZE_ARRAY];
int i, key;
// Make sure the file exists
if(!inputFile)
{
cout << endl << "The File is corrupt or does not exist. " << filename;
return 1;
}
long n = 0;
while(!inputFile.eof())
{
inputFile >> n;
numbers = cout << std::setw(10) << n;
}
for(int j=1;j<5;j++)
{
i=j-1;
key=numbers[j];
while(i>=0 && numbers[i]>key)
{
numbers[i+1]=numbers[i];
i--;
}
numbers[i+1]=key;
}
//Display sorted array
cout<<endl<<"Sorted Array\t";
for(i=0;i<5;i++)
cout<<numbers[i]<<"\t";
cout<<endl;
}