현재 텍스트 파일에서 출력 할 수있는 코드 조각을 만들었습니다. 텍스트를 읽고 각기 다른 정보를 배열에 넣습니다.배열 배열을 해당 배열로 정렬
저장하려는 정보가 4 가지이므로 4 가지 배열을 사용했습니다. 이 코드는 예상대로 작동하지만 배열 중 하나가 사전 순으로 정렬 된 방식으로 정보를 정렬 할 수있는 방법이 확실하지 않으며 모든 해당 배열이 올바른 시간에 출력되고 출력됩니다.
void displayfile(){
string filename1;
string rartist[NUM];
string rtitle[NUM];
string ryear[NUM];
string rcategory[NUM];
ifstream openFile;
int counter = 0;
int continu
bool error = false;
cout << "test";
do{
//Loop to retrieve the file name from user, then open file
do{
cout << "Please enter the name of the menu you would like to open: ";
cin >> filename1;
filename1 += ".txt";
openFile.open(filename1.c_str());
if(openFile.fail()){
cerr << "Check spelling of file name.\n";
error = true;
}
//Storing text from file into arrays
}while(error == true);
while(getline(openFile, rartist[counter], ':') && getline(openFile, rtitle[counter], ':') &&
getline(openFile, ryear[counter], ':') && getline(openFile, rcategory[counter])){
counter++;
}
//outputting the information stored in the array
cout << "ARTIST " << " DVDTITLE " << " YEAR " << " CATEGORY \n";
for(int i = 0; i < counter; i++){
cout << rartist[i] << " " << rtitle[i] << " "
<< ryear[i] << " " << rcategory[i] << "\n";
}
cout << "\n\nIf you would like to read another file, Press 1: ";
cin >> continu;
}while(continu == 1)
}
이것은 현재 텍스트를 표시하는 데 사용하는 기능입니다.
가장 쉬운 방법은 관련 항목이 아닌 각 항목 유형에 대해 별도의 배열을 포함하는 구조의 단일 배열을 수 있도록 데이터를 재구성하는 것입니다. –
이 기능을 유지하고 다른 옵션으로 정렬을 수행하는 새 기능을 생성 할 때 이것이 내가 필요한 것일 수 있습니다. 고마워, 이제 이걸 들여다 봐라. – Thecube