我正在尝试编写一个允许用户跟踪其 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();
}