我正在尝试为学校生成一个测验程序。我的代码如下
主.cpp:
#include <cmath>
#include <ctime>
#include <string>
#include "getQuestion.h"
using namespace std;
int main() {
int mainMenuChoice;
ifstream Bibliography;
//string easyBib;
ifstream easyBib;
ifstream inputFile;
cout << "Quiz Menu\n\n";
cout << "1. Play Game!\n";
cout << "2. Bibliography\n";
cout << "3. Developer Info\n";
//cout << "4. Admin Menu\n";
cout << "4. Exit\n";
cout << "Menu Choice: ";
cin >> mainMenuChoice;
switch (mainMenuChoice) {
case 1:
break;
case 2:
inputFile.open("Bib.txt");
inputFile >> easyBib;
cout << easyBib << endl;
break;
case 3:
break;
/*case 4:
break;*/
case 4:
cout << "Thank you for playing!" << endl;
return(0);
default:
cout << "Sorry, Invalid Choice!\n";
return(0);
}
return(0);
}
获取问题.h:
#ifndef getQuestion
#define getQuestion
int getQuestion () {
ifstream Question;
ifstream Linker; //Linker for 2 flies
ifstream Answer;
string A;
string L; //Linker for 2 flies
string Q;
int line;
Question.open("Question.txt");
Question >> Q;
Answer.open("Answer.txt");
Answer >> A;
Linker.open("Linker.txt");
Linker >> L;
getline(Question,line);
number_of_lines++;
#endif
编译器错误:
Build Social Studies of project Social Studies with configuration Debug
CompileC "build/Social Studies.build/Debug/Social Studies.build/Objects-normal/x86/main.o" main.cpp normal x86_64 c++ com.apple.compilers.gcc.4_2
cd "/Users/student/Desktop/Social Studies"
setenv LANG en_US.US-ASCII
/Developer/usr/bin/gcc-4.2 -x c++ -arch x86_64 -fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -fasm-blocks -O0 -Wreturn-type -Wunused-variable -isysroot /Developer/SDKs/MacOSX10.6.sdk -mfix-and-continue -fvisibility-inlines-hidden -mmacosx-version-min=10.6 -gdwarf-2 -iquote "/Users/student/Desktop/Social Studies/build/Social Studies.build/Debug/Social Studies.build/Social Studies-generated-files.hmap" "-I/Users/student/Desktop/Social Studies/build/Social Studies.build/Debug/Social Studies.build/Social Studies-own-target-headers.hmap" "-I/Users/student/Desktop/Social Studies/build/Social Studies.build/Debug/Social Studies.build/Social Studies-all-target-headers.hmap" -iquote "/Users/student/Desktop/Social Studies/build/Social Studies.build/Debug/Social Studies.build/Social Studies-project-headers.hmap" "-F/Users/student/Desktop/Social Studies/build/Debug" "-I/Users/student/Desktop/Social Studies/build/Debug/include" "-I/Users/student/Desktop/Social Studies/build/Social Studies.build/Debug/Social Studies.build/DerivedSources/x86_64" "-I/Users/student/Desktop/Social Studies/build/Social Studies.build/Debug/Social Studies.build/DerivedSources" -c "/Users/student/Desktop/Social Studies/main.cpp" -o "/Users/student/Desktop/Social Studies/build/Social Studies.build/Debug/Social Studies.build/Objects-normal/x86_64/main.o"
In file included from /Users/student/Desktop/Social Studies/main.cpp:8:
/Users/student/Desktop/Social Studies/getQuestion.h:4: error: expected unqualified-id before 'int'
/Users/student/Desktop/Social Studies/getQuestion.h:4: error: expected `)' before 'int'
谢谢。另外请不要吝啬,我是编程新手!我正在使用 Mac OS X v. 10.6.8 和 XCode 3.2.6 在有人要求我升级任何东西之前,我不是管理员(这是一台学校笔记本电脑)
编辑:感谢大家的帮助!代码中是否还有其他问题(与性能有关?)