我正在使用C ++编写这个GUI,它应该询问输入.txt文件的路径,然后输出路径创建一个格式化的输出文件。我点击“报告”按钮后会尝试打开一个消息框,该按钮将计算输入文件中的项目数并显示该数字。我正在做它作为一个结构,我不知道如何使它工作。请给我一个这方面。这完全来自我的Form.h文件。我将跳过所有窗口生成的代码到安全空间。
#pragma once
//declare structure and variables at the top of form code
#pragma region Global Declarations
struct PetData
{
int IdNumber;
char PetType[25];
//Count and display the number of items in the linked list
int CountItems;
PetData * Link;
};
PetData *Headpointer = NULL;
ifstream DataFile;
ofstream FileOut;
void InsertItem ( int, char[], PetData* );
void OutputItem ( PetData*);
#pragma endregion
namespace GilleyFinalExamSample {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
//include these libraries
using namespace System::IO;
using namespace System::Runtime::InteropServices;
现在我要了解我添加的内容
#pragma endregion
private: System::Void ExitButton_Click(System::Object^ sender, System::EventArgs^ e)
{
Application::Exit();
}
private: System::Void InputFileBox_Click(System::Object^ sender, System::EventArgs^ e)
{
InputFileBox->Clear();
OutputFileBox->Clear();
}
private: System::Void CreateFileButton_Click(System::Object^ sender, System::EventArgs^ e)
{
PetData *CurrentRecordPointer;
int InitIdNumber =0;
char InitPetType[25] = "\0";
// get the filename and store it in inputFilename
char* InputFileName;
InputFileName = (char*)(void*)Marshal::StringToHGlobalAnsi(InputFileBox->Text);
DataFile.open ( InputFileName );
//validation check
if (!DataFile )
{
Application::Exit( );
}//end of if stmt
//get filename and store in OutputFileName
char* OutPutFileName;
OutPutFileName = (char*)(void*)Marshal::StringToHGlobalAnsi( OutputFileBox->Text);
FileOut.open (OutPutFileName );
//validation check
if (!FileOut)
{
Application::Exit();
}//end of if stmt
//priming read
DataFile >> InitIdNumber;
DataFile.ignore( );
DataFile.get (InitPetType, 7 );
while ( DataFile )
{
CurrentRecordPointer = new PetData;
InsertItem(InitIdNumber, InitPetType, CurrentRecordPointer);
Headpointer = CurrentRecordPointer;
DataFile >> InitIdNumber;
DataFile.ignore( );
DataFile.get (InitPetType, 7 );
}//end of while loop
OutputItem ( Headpointer );
FinalMessage->Visible=true;
//cleanup
DataFile.close( );
FileOut.close( );
delete CurrentRecordPointer;
Headpointer = NULL;
}//end brace of create file button
//define Insert and output functions
void InsertItem ( int InitIdNumber, char InitPetType[ ], PetData* CurrentRecordPointer )
{
CurrentRecordPointer->IdNumber = InitIdNumber;
strcpy_s (CurrentRecordPointer->PetType, InitPetType);
CurrentRecordPointer->Link = Headpointer;
return;
}//close brace of InsertItem
void OutputItem ( PetData *FirstRecord )
{
FileOut << " Pet Data " << endl << endl;
FileOut << " Id Number Pet Type " << endl;
while (FirstRecord != NULL)
{
FileOut << FirstRecord->IdNumber
<< " "
<<FirstRecord->PetType
<<endl;
FirstRecord = FirstRecord->Link;
}//end of while
return;
}//close brace of OutputItem Function
};
}
不要介意它说“期末考试”这只是决赛的练习。非常感谢你的帮助