【发布时间】:2014-01-20 06:19:45
【问题描述】:
我是 C++ 新手,我正在开发一个程序,学生可以在其中键入他们的主题代码,然后会有一个菜单可供选择。
问题是,在键入并输入主题代码后,将出现菜单及其选项,但您退出系统而不是选择继续的选项..
这是我试图让它们工作的部分的代码
void ProcessStudent(char option, char subjCode)
{
fstream binFile;
const char *fileName;
cout << "Welcome to Priya's UOW Student File Processing\n" << endl;
cout << "Enter the module: ";
cin >> subjCode;
cout << "\n1. Creation of binary file\n";
cout << "2. Append a record\n";
cout << "3. Update a record\n";
cout << "4. Delete a record\n";
cout << "5. Produce final file (text file)\n";
cout << "9. Quit\n";
cout << "Your option: ";
cin >> option;
cout << "\n" <<setw(60)<<setfill('-')<<'-'<<endl;
switch(option)
{
case '1':
CreateBinary(binFile,subjCode,fileName);
break;
case '2':
AppendRec(binFile,option,fileName);
break;
case '3':
UpdateRec(binFile,option,fileName);
break;
case '4':
DeleteRec(binFile,option,fileName);
break;
case '5':
FinalFile(binFile,option,fileName);
break;
case '9':
MainMenu(option);
}
}
void CreateBinary(fstream& binFile, char subjCode, const char *fileName)
{
// Student s;
srand(time(NULL));
binFile.open(fileName, ios::out | ios::binary);
// binFile >> s.id;
// binFile.getline(s.name,MAX);
if(!binFile)
{
cout << fileName << " opened for creation failed" << endl;
exit(-1);
}
cout << "Begin creation of " << fileName << endl;
fstream txtFile;
txtFile.open(fileName, ios::in);
if(!txtFile)
{
cout << fileName << " opened for reading failed" << endl;
exit(-1);
}
cout << "Text file " << fileName << "opened for reading" << endl;
binFile.close();
txtFile.close();
cout << "Binary file " << fileName << " created" << endl;
cout << "Text file " << fileName << " closed for reading" << endl;
}
我要问的是,我输入主题代码或任何其他字符串后如何选择选项?我错过了代码中的任何内容吗?
希望你们明白我在问什么,如果没有,请告诉我。
感谢您提供任何帮助。非常感谢:)。
【问题讨论】:
-
哪个编译器,你是怎么编译的,哪个操作系统?并展示更多代码,并说明你是如何调试它的。
-
我使用 Quincy 编译。遗憾的是,由于声誉问题,我无法截取该程序的屏幕截图……抱歉。
标签: c++ string selection iostream submenu