我试图设置一个计数器功能,该功能将计算输入文件中的项目数并在消息框中显示答案。我想我已经接近但我似乎无法让它正常工作。 这是我的结构。
#pragma region Global Declarations
#include <iostream>
#include <fstream>
#include <iomanip>
struct PetData
{
int IdNumber;
char PetType[25];
double PetPrice;
//Count and display the number of items in the linked list
int CountItems;
PetData * Link;
};
PetData *Headpointer = NULL;
ifstream DataFile;
ofstream FileOut;
//Create a report listing the records
//that currently comprise the linked list
void ListRecords ( char * );
void InsertItem ( int, char[],double, PetData* );
void OutputItem ( PetData*);
#pragma endregion
这就是我对柜台的所作所为
OutputItem ( Headpointer );
//FinalMessage->Visible=true;
Headpointer->ListRecords ( OutPutFileName );
MessageBox::Show ("Listed Printed To Output File \n"
+ Headpointer->CountItems + " Items Were Printed",
"Report Created", MessageBoxButtons::OK,
MessageBoxIcon::Information);
//cleanup
DataFile.close( );
FileOut.close( );
delete CurrentRecordPointer;
Headpointer = NULL;
我感谢您提供的任何帮助。谢谢
答案 0 :(得分:0)
#pragma region Global Declarations
#include <Windows.h>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <sstream>
class LinkedList
{
public:
struct PetData
{
int IdNumber;
char PetType[25];
double PetPrice;
//Count and display the number of items in the linked list
PetData * Link;
};
private:
PetData *Headpointer;
ifstream DataFile;
ofstream FileOut;
void DeleteItems();
public:
LinkedList():Headpointer(NULL)
{
OutputItem ( Headpointer );
};
~LinkedList()
{
DataFile.close( );
FileOut.close( );
DeleteItems();
}
//Create a report listing the records
//that currently comprise the linked list
void ListRecords (const char * );
void InsertItem ( int, char[],double, PetData* );
void OutputItem ( PetData*);
int CountItems();
};
#pragma endregion
const char * OutPutFileName="out.file";
LinkedList * list = new LinkedList();
//FinalMessage->Visible=true;
list->ListRecords ( OutPutFileName );
wstringstream ss;
ss<<"Listed Printed To Output File \n" << list->CountItems() << " Items Were Printed";
MessageBox(NULL, ss.str().c_str(), TEXT("Report Created"), MB_OK|MB_ICONINFORMATION);
//cleanup
答案 1 :(得分:0)
你有这个:
Headpointer->ListRecords ( OutPutFileName );
相当于
(*Headpointer).listRecords(OutputFileName);
但* Headpointer是一个没有listRecords函数的PetData。该函数在struct之外声明。