這應該很簡單,我發現第一個參數是數組名稱,第二個參數是數組的大小+數組名,但似乎沒有在所有排序,實際上它沒有做任何事情,也沒有在控制檯上寫任何東西,我在做別的什麼傻?std :: sort()C++沒有工作,但它很簡單,爲什麼:(1D數組
int main()
{
readFromFile();
system("pause");
return 0;
}
void readFromFile()
{
string line;
int i = 0;
int j;
ifstream file("ACW2_data.txt");
if(file.is_open())
{
getline(file, line);
while (!file.eof())
{
file >> numbers[i];
i++;
int elements = sizeof(numbers)/sizeof(numbers[0]);
**sort(numbers, numbers + elements);**
}
file.close();
}
else
{
cout << "Cant open the file" << endl;
}
for(j = 0; j < i; j++)
{
cout << numbers[j] << endl;
}
system("pause");
}
你們覺得呢?
'numbers'的類型是什麼? – 2011-04-18 19:41:53
你的文件是什麼樣的? – 2011-04-18 19:43:09
'數字'是一個指針嗎?它如何分配?爲什麼在每個數字讀取後進行排序,而不是先讀取所有數字,然後再進行排序? – hammar 2011-04-18 19:43:28