C++ 如何在C++;工作
我正在尝试设置一个计数器函数,该函数将计算输入文件中的项目数,并在消息框中显示答案。我想我很接近,但我似乎无法让它正常工作。 这是我的结构C++ 如何在C++;工作,c++,linked-list,counter,C++,Linked List,Counter,我正在尝试设置一个计数器函数,该函数将计算输入文件中的项目数,并在消息框中显示答案。我想我很接近,但我似乎无法让它正常工作。 这是我的结构 #pragma region Global Declarations #include <iostream> #include <fstream> #include <iomanip> struct PetData { int IdNumber; char PetType[25]; double
#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
我很感激你能给我的任何帮助。谢谢您可能需要类似的东西吗
#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
#pragma区域全局声明
#包括
#包括
#包括
#包括
#包括
类链接列表
{
公众:
结构PetData
{
国际电话号码;
char-PetType[25];
双倍价格;
//计算并显示链接列表中的项目数
PetData*链接;
};
私人:
PetData*头指针;
ifstream数据文件;
流文件输出;
作废删除项目();
公众:
LinkedList():头指针(NULL)
{
输出项(头指针);
};
~LinkedList()
{
close();
FileOut.close();
删除项目();
}
//创建一个列出记录的报告
//目前包含链接列表的
无效列表记录(常量字符*);
void插入项(int,char[],double,PetData*);
无效输出项(PetData*);
int CountItems();
};
#布拉格端区
const char*OutPutFileName=“out.file”;
LinkedList*列表=新建LinkedList();
//最终消息->可见=真;
列表->列表记录(OutPutFileName);
wstringstreamss;
ss你有这个:
Headpointer->ListRecords ( OutPutFileName );
这相当于
(*Headpointer).listRecords(OutputFileName);
但是*Headpointer是一个没有listRecords函数的PetData。该函数是在结构外部声明的。您能不能比“我似乎无法使它正常工作”更具体一些?
(*Headpointer).listRecords(OutputFileName);