我将如何在数组中使用 include() 函数?
例如,我有一个列出一堆县的数组,我没有将所有县输入到数组中,而是创建了一个以逗号分隔的县的 .txt 文件。从逻辑上讲,我认为它应该这样工作:
array (include ("counties.txt"));
但它会在数组函数之外生成列表。
是否有在数组中使用 include() 函数的不同方法?
我试图应用一个补丁,它允许我使用std::to_string(). 我在 rm 上使用/usr/include/wchar.h,然后将wchar.h我下载的修补程序复制到 /usr/include 目录。现在,当我尝试编译程序时,它抱怨找不到_mingw.h
在这一点上,我只想找到一种方法来获取旧的副本wchar.h并替换“修补”的副本。我会找到一种方法来做到这一点std::to_string();
基本上是这样的:
Car 和 Truck 都派生自 Vehicle 类。
车.h
#include "Vehicle.h"
class Car : public Vehicle {
//blah blah blah
Run Code Online (Sandbox Code Playgroud)
卡车.h
#include "Vehicle.h"
class Truck : public Vehicle {
//blah blah blah
Run Code Online (Sandbox Code Playgroud)
主程序
#include "Car.h"
#include "Truck.h"
Run Code Online (Sandbox Code Playgroud)
我的问题是,当我在那里有 #include 行时,我在 Truck 上收到类重新定义错误(由于它第二次调用 Vehicle),但是当我删除它时,我有“{ token”之前的预期类名。
我得到了 Main -> Car -> Vehicle Main -> Truck -> Vehicle(重新定义)
会导致错误。
但是如果我从 Truck 中删除 #include "Vehicle.h" 它也会导致另一个错误,它需要一个类名。
上面的问题是一样的。
因为当我编译我的 C 程序时它给了我一个致命错误(没有找到 graphics.h),我想知道我可以用什么来代替它。
考虑到我不想链接到其他网站或其他任何内容,因为我是新手,我不明白。
我只需要输入命令即可使其工作。如果我必须下载一个库,那么没关系,只要您指导我完成整个过程。
谢谢。
这是我正在尝试编译的内容
创建笑脸的代码。
#include <graphics>
int main(void)
{
int midX, midY,
leftEyeX, rightEyeX, eyeY,
noseX, noseY,
headRadius,
eyeNoseRadius,
smileRadius,
stepX, stepY,
initwindow(500, 400, "Happy Face - press key to close", 200, 150);
midX = getmaxx() / 2;
midY = getmaxy() / 2;
headRadius = getmaxy() / 4;
circle(midX, midY, headRadius);
stepX = headRadius / 4;
stepY = stepX;
leftEyeX = midX - stepX;
eyeY = midY - stepY;
eyeNoseRadius = headRadius / 10; …Run Code Online (Sandbox Code Playgroud) 我的.cpp和.h文件的路径: /home/quasiturbine/ServerProject/Network/NetworkIncludes/
在那里你可以找到TCP_Connexion.h和TCP_Connexion.cpp
在.cpp文件中,我得到了#include "NetworkIncludes\TCP_Connexion.h"默认的构造函数/析构函数.而已.
G ++命令:
g++ -o program -I/home/quasiturbine/ServerProject/Network/ /home/quasiturbine/ServerProject/Network/NetworkIncludes/TCP_Connexion.cpp
Run Code Online (Sandbox Code Playgroud)
致命错误:/home/quasiturbine/ServerProject/Network/NetworkIncludes/TCP_Connexion.cpp:1:43:致命错误:NetworkIncludes\TCP_Connexion.h:没有这样的文件或文件夹#include"NetworkIncludes\TCP_Connexion.h"
有什么问题,我该如何解决?
我对#includeC++中的预处理程序指令有疑问.
在我的程序中,我想包含另一个目录中的头文件.为此,我使用了完整路径,例如:
#include "full/path/to/my/header.hpp"
Run Code Online (Sandbox Code Playgroud)
现在事实证明它header.hpp本身有一个包含(比方说#include "otherheader.hpp".在编译期间,编译器抱怨它找不到这个其他标题.
考虑到我也不想为每个头文件编写完整路径这一事实,尤其是那些只需要"进一步向下"的文件,这是处理这个问题的最佳方法是什么?
我就是不明白为什么这不会编译。
我有三个文件:
主程序
#include "expression.h"
int main(int argc, char** argv)
{
return 0;
}
Run Code Online (Sandbox Code Playgroud)
表达式.h
#ifndef _EXPRESSION_H
#define _EXPRESSION_H
namespace OP
{
char getSymbol(const unsigned char& o)
{
return '-';
}
};
#endif /* _EXPRESSION_H */
Run Code Online (Sandbox Code Playgroud)
和表达式.cpp
#include "expression.h"
Run Code Online (Sandbox Code Playgroud)
(Ofc 里面还有更多内容,但即使我评论除了#includeout之外的所有内容,它也不起作用)
我编译它
g++ main.cpp expression.cpp -o main.exe
Run Code Online (Sandbox Code Playgroud)
这是我得到的错误:
C:\Users\SCHIER~1\AppData\Local\Temp\ccNPDxb6.o:expression.cpp:(.text+0x0): multiple definition of `OP::getSymbol(unsigned char const&)'
C:\Users\SCHIER~1\AppData\Local\Temp\cc6W7Cpm.o:main.cpp:(.text+0x0): first defined here
collect2.exe: error: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
问题是,它似乎解析expression.h了两次。如果我只是使用main.cppOR编译它,expression.cpp我就不会收到错误消息。编译器只是忽略我的 #ifndef 并继续......
有什么线索吗?
我正在尝试在我的RHEL 5机器上编译google rpc(grpc),配置脚本检查并抛出此错误:
configure: error: sched_yield was not found on your system
Run Code Online (Sandbox Code Playgroud)
我检查了config.log文件,发现是这样的:
| /* Override any GCC internal prototype to avoid an error.
| Use char because int might match the return type of a GCC
| builtin and then its argument prototype would still apply. */
| #ifdef __cplusplus
| extern "C"
| #endif
| char sched_yield ();
| int
| main ()
| {
| return sched_yield ();
| ;
| return 0;
| }
configure:19729: result: …Run Code Online (Sandbox Code Playgroud) 我想使用字符串类。我还应该参与using namespace std;吗?
我以为#include <string>就足够了,但是在CLion中,只有这两个(命名空间或包含)之一不存在时,会出现一些错误。
使事情变得更复杂的是存在<string>或<strings.h>。有什么不同?
假设我们有一个头文件A.h,它依赖于B.h和中声明的内容C.h。B.h也取决于C.h,因此也包括在内。在这种情况下,我们不需要包含C.h进去A.h,没有它就可以编译。
但是我想知道在这些情况下最好的行动方案是什么。如果B.h以某种方式更改并且不再依赖C.h,A.h则会中断。
另一方面,如果我认为到最后,重新包含所有单个依赖关系似乎是不必要/不切实际的。
我常见的情况是标准库。在几乎所有的头文件中,我都必须包含<stdint.h>和<stdbool.h>。我经常跳过它,因为它们已经包含在其中一个依赖项中,但这总是感觉有些武断。