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
이 코드는 웹 페이지에서 ** 아무것도 ** ** 않습니다. 파일에서 "보석"데이터를 읽고 이름으로 정렬합니다. 'system ("pause"); 줄은 종료 전에 키 누르기를 기다리는 프로그램을 만듭니다. – egrunin
yyes 쥬얼리 데이터를 읽고 정렬합니다 .. 그러나 컴파일되고 실행될 때 아무 키도 누르지 않으면 아무 것도 나타나지 않습니다. – Taylor
어떤 결과를 기대합니까? 질문에 대한 자세한 정보가 필요합니다. – Sampson