我试图编译文件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;
}
SavingsAccount.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
对此问题的任何输入将不胜感激。
只有系统内置头用作'的#include'。除了那些复制到系统包含路径(不推荐)的路径之外,你自己的自定义头文件必须用作'#include“myheader.h”' –
phoeagon
2013-04-22 02:15:02