我正在尝试设置一个计数器函数,该函数将计算输入文件中的项目数并在消息框中显示答案。我想我很接近,但我似乎无法让它正常工作。这是我的结构。
#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;
感谢您提供的任何帮助。 谢谢
也许你需要类似的东西?
#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
你有这个:
Headpointer->ListRecords ( OutPutFileName );
这等同于
(*Headpointer).listRecords(OutputFileName);
但 *Headpointer 是一个没有 listRecords 函数的 PetData。该函数在结构外部声明。