2010-05-06 64 views
0

我試圖將數據從網頁複製到結構數組中並在生成數據之前按「名稱」進行排序。當我運行這個程序時,它說按任意鍵繼續?這個程序爲什麼提示我'按任意鍵繼續'?

#include <iostream> 
#include <string> 
#include <iomanip> 
#include <fstream> 
using namespace std; 

struct productJewelry 
{ 
     string name; 
     double amount; 
     int itemCode; 
     double size; 
     string group;  
}; 

int main() 
{ 
    // declare variables 
    ifstream inFile; 
     int count=0; 
     int x=0; 

     productJewelry product[50]; 

    inFile.open("jewelry.txt"); // file must be in same folder 
if (inFile.fail()) 
cout << "failed"; 
    cout << fixed << showpoint; // fixed format, two decimal places 
    cout << setprecision(2); 

    while (inFile.peek() != EOF) 
    { 
//   cout << count << " : "; 
     count++; 
     inFile>> product[x].itemCode; 
     inFile>> product[x].name; 
     inFile>> product[x].size; 
     inFile>> product[x].amount; 
     inFile>> product[x].group; 
//   cout << product[x].itemCode << ", " << product[x].name << ", "<< product[x].size << ", " << product[x].amount << endl; 
     x++; 
     if (inFile.peek() == '\n') 
      inFile.ignore(1, '\n'); 
    } 

    inFile.close(); 
string temp; 
bool swap; 
     do 
     { 
      swap = false; 
      for (int x=0; x<count;x++) 
      { 
      if (product[x].name>product[x+1].name) 
      { 
       //these 3 lines are to swap elements in array 
       temp=product[x].name; 
       product[x].name=product[x+1].name; 
       product[x+1].name=temp; 
       swap=true; 
      } 
      } 
     } while (swap); 

     for (x=0; x< count; x++) 
     { 
     //cout<< product[x].itemCode<<" "; 
     //cout<< product[x].name <<" "; 
     //cout<< product[x].size <<" "; 
     //cout<< product[x].amount<<" "; 
     //cout<< product[x].group<<" "<<endl; 

     } 

    system("pause"); // to freeze Dev-c++ output screen 
    return 0; 
} // end main 
+1

此代碼沒有任何**與網頁。它從文件中讀取「珠寶」數據並按名稱排序。 'system'(「pause」)行讓程序在退出之前等待按鍵。 – egrunin 2010-05-06 17:20:23

+0

yyes它讀取珠寶數據並對其進行排序..但是,當它被編譯並且什麼也沒有顯示時除了按任何鍵以外繼續 – Taylor 2010-05-06 18:09:34

+0

您期待什麼結果?您的問題需要更新以獲取更多信息。 – Sampson 2010-05-06 19:23:30

回答

2

它說:「按任意鍵繼續」,因爲這是pause程序調用什麼用呢system("pause")

它不輸出任何東西,因爲你已經註釋掉了所有輸出語句

相關問題