2014-12-04 56 views
-3

我試圖設置一個計數器函數,它將計算輸入文件中的項目數並在消息框中顯示答案。我認爲我很接近,但我似乎無法讓它正常工作。 這裏是我的結構。如何在C++中使用這個計數器函數?

#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; 

我感謝所有幫助你可以給。謝謝

+1

你能比「我似乎無法讓它正常工作」更具體嗎? – molbdnilo 2014-12-04 14:47:34

回答

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 
0

你有這樣的:

Headpointer->ListRecords (OutPutFileName); 

這是equivelent到

(*Headpointer).listRecords(OutputFileName); 

但* Headpointer是PetData不具有listRecords功能。該函數在結構體外聲明。

相關問題