2010-05-06 4 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

+0

yyes 쥬얼리 데이터를 읽고 정렬합니다 .. 그러나 컴파일되고 실행될 때 아무 키도 누르지 않으면 아무 것도 나타나지 않습니다. – Taylor

+0

어떤 결과를 기대합니까? 질문에 대한 자세한 정보가 필요합니다. – Sampson

답변

2

그것은 말한다는 system("pause")을 수행하여 pause 프로그램이 호출 무엇 때문에 "계속하려면 아무 키를 누르십시오."

은 출력 문을 모두 주석 처리 했으므로 아무 것도 출력하지 않습니다.

관련 문제