我「米試圖寫一個程序,允許用戶跟蹤他們的DVD。使用輸入文件,其中包括每個電影這些屬性。輸出鏈接列表?
基本上,用戶應該能夠在輸入文件的名稱進入。 使用結構和指針,創造了輸入文件中的影片的鏈接列表。 接下來,輸出鏈表到輸出文件。 格式情節的輸出,它會自動換行。
輸出假設看起來像這樣
***************************************************************************
MOVIE #: 1 Title: Antwone Fisher
---------------------------------------------------------------------------
Year: 2002 Rating: 7
---------------------------------------------------------------------------
Leading Actor: Denzel Washington Genre 1: Biography
Supporting Actor: Derek Luke Genre 2: Drama
---------------------------------------------------------------------------
PLOT:
Antwone Fisher, a young navy man, is forced to see a psychiatrist after a
violent outburst against a fellow crewman. During the course of treatment
a painful past is revealed and a new hope begins.
***************************************************************************
到目前爲止,問題是我的輸出,我無法顯示輸出。我試圖調試它,結果我被困在while循環中。
這裏是我的輸出功能
void OutputList(MovieDVD *head)
{
ofstream OFile;
OFile.open("OFile.txt");
MovieDVD *dvdPtr;
dvdPtr = head;
cout << "Before While Output " << endl;
while(dvdPtr != NULL)
{
OFile << left;
OFile << dvdPtr -> title;
OFile << dvdPtr -> leadActor;
OFile << dvdPtr -> supportActor;
OFile << setfill('*') << setw(25) << '*' << endl;
OFile << dvdPtr -> genre;
OFile << setfill('*') << setw(25) << '*' << endl;
OFile << dvdPtr -> altGenre;
OFile << setfill('*') << setw(25) << '*' << endl;
OFile << dvdPtr -> year;
OFile << setfill('*') << setw(25) << '*' << endl;
OFile << dvdPtr -> rating;
OFile << setfill('*') << setw(25) << '*' << endl;
OFile << dvdPtr -> synopsis;
OFile << setfill('*') << setw(25) << '*' << endl;
dvdPtr = dvdPtr -> next;
cout << endl;
cout << "READ - AFTER LINE OUTPUT" << endl;
}
cout << " DEBUG -- AFTER WHILE OUTPUT" << endl;
delete dvdPtr;
dvdPtr = NULL;
OFile.close();
}
Here my main function:
//INPUT OUTPUT FILE DECLARATION
ifstream inFile; //INPUT FILE declaration
ofstream OFile; //OUTPUT FILE declaration
//VARIABLE DECLARATION
string inputFileName; //IN - Input file name
string outputFileName; //OUT - Output file name
string synopsis;
MovieDVD *head;
MovieDVD theMovie;
head = NULL;
//INPUT
cout << "What input file would you like to use?: ";
getline(cin, inputFileName);
cout << "DEBUG -- BEFORE CREATELIST "<< endl;
CreateList(head, inputFileName);
cout << "DEBUG -- AFTER CREAETLIST " << endl;
//OUTPUT LIST
cout << "What output file would you like to use?: ";
getline(cin, outputFileName);
OutputList(head);
WordWrap(OFile, head, synopsis);
我添加COUT爲我調試輸出名單上,只有 cout << "Before While Output " << endl
和cout << " DEBUG -- AFTER WHILE OUTPUT" << endl
出來,跳過while循環。請幫幫我。
我的創意列表功能
void CreateList(MovieDVD *head, string inputFileName)
{
ifstream inFile;
inFile.open("inFile.txt");
MovieDVD *dvdPtr;
head = NULL;
dvdPtr = NULL;
dvdPtr = new MovieDVD;
int counter =0;
cout << " DEBUG -- BEFORE WHILE" << endl;
while (inFile && (dvdPtr != NULL))
{
getline(inFile, dvdPtr -> title);
getline(inFile, dvdPtr -> leadActor);
getline(inFile, dvdPtr -> supportActor);
getline(inFile, dvdPtr -> genre);
getline(inFile, dvdPtr -> altGenre);
inFile >> dvdPtr -> year;
inFile >> dvdPtr -> rating;
inFile.ignore(1000, '\n');
getline(inFile, dvdPtr -> synopsis);
dvdPtr -> next = head;
head = dvdPtr;
dvdPtr = new MovieDVD;
cout << "READ line " << counter++ << endl;
}
cout << " DEBUG -- AFTER WHILE" << endl;
delete dvdPtr;
dvdPtr = NULL;
inFile.close();
}
您需要向我們展示'CreateList'函數。 – codaddict
輸出文件是否成功打開/創建? – SingerOfTheFall
輸出文件未成功打開。當我調試時,它不會經過while循環。 – retrofusion