我正在尝试编译文件q1.cpp但我不断收到编译错误:
q1.cpp:2:28: fatal error: SavingsAccount.h: No such file or directory
compilation terminated.
头文件和头文件的实现都在与q1.cpp完全相同的目录中。
文件如下:
q1.cpp:
#include <iostream>
#include <SavingsAccount.h>
using namespace std;
int main() {
SavingsAccount s1(2000.00);
SavingsAccount s2(3000.00);
}
SavingsAccount.cpp:
#include <iostream>
#include <SavingsAccount.h>
using namespace std;
//constrauctor
SavingsAccount::SavingsAccount(double initialBalance) {
savingsBalance = initialBalance;
}
SavingsAccount::calculateMonthlyInterest() {
return savingsBalance*annualInterestRate/12
}
SavingsAccount::modifyInterestRate(double new_rate) {
annualInterestRate = new_rate;
}
储蓄账户.h:
class SavingsAccount {
public:
double annualInterestRate;
SavingsAccount(double);
double calculateMonthlyInterest();
double modifyInterestRate(double);
private:
double savingsBalance;
};
我想重申所有文件都在同一个目录中。我正在尝试在 Windows 命令提示符下使用此行进行编译:
C:\MinGW\bin\g++ q1.cpp -o q1
对此问题的任何输入将不胜感激。