g++找不到我的头文件
g++ is unable to find my header file
我试图编译文件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:MinGWbing++ q1.cpp -o q1
对这个问题的任何投入都将不胜感激。
#include <SavingsAccount.h>
应该是
#include "SavingsAccount.h"
由于SavingsAccount.h
是您定义的头文件,您不应该要求编译器使用<>
来搜索系统头文件。
同时,在编译它时,应该同时编译两个cpp文件:SavingsAccount.cpp
和q1.cpp
。
g++ SavingsAccount.cpp q1.cpp -o q1
BTW:你错过了;
这里:
SavingsAccount::calculateMonthlyInterest() {
return savingsBalance*annualInterestRate/12;
//^^; cannot miss it
}
相关文章:
- 如何指定我希望我的LIB链接到的DLL文件?-Visual Studio 2019
- 我的程序没有从文件中读取并输入数据
- 为什么我的 heap.h 文件给我一个LNK2001错误?
- 我的程序有一个保存配置文件的GUI,如何双击此配置文件以直接加载带有配置数据的GUI?
- 为什么当我输入较大的数字时,我的程序会到达文件末尾?
- CMake:在其他目录中找不到我的头文件
- 如何在Visual Studio Code中重命名我的a.exe文件?
- 如何格式化我的文本文件以使其不会一遍又一遍地重复同一行?
- 查找定义我的 C/C++ 函数/宏的文件比'grep'更简单的方法
- 我的文件无法正常工作,无法从C++文件中读取上下文
- 我的 SDL2 程序需要哪些二进制文件,以便它在另一台未安装 SDL2 的计算机中工作
- 为什么我的程序在读取/写入文件时会删除最重要的数字?
- 我的头文件 DNode 中的我的数据类型未被识别为数据类型
- 将内容从第一个文件("constituencies")移动到第二个文件("temp")并在之后重命名时,我的文件被删除
- 如何在我的 Visual C++ 项目中使用 .a 文件
- 为什么我不能从同一目录中的另一个文件中 #include 我的类?
- 如何将我的程序添加到文件和文件夹的macOS右键单击菜单?
- 如何自动获取我的项目的路径并删除一些文件
- :-1: 错误: LNK1104: 无法打开文件"我的项目.obj"
- C++创建进程 - 系统错误#2找不到文件 - 我的文件路径有什么问题?