在 C++ 的 .h 中包含 .txt 文件?

发布于 2024-08-11 03:34:04 字数 190 浏览 4 评论 0原文

我有很多地方需要重复使用一些模板代码。许多类需要这些项目

在 .h 中我可以做类似的事情:

#include <xxx.txt>

并将所有这些代码放在 .txt 中并仅将其包含在内吗?

类似 PHP 的东西包含!

gcc 允许这样做吗?

I have a number of places where I need to re-use some template code. Many classes need these items

In a .h could I do something like:

#include <xxx.txt>

and place all of this code in the .txt and just have it included?

Something like a PHP include!

Does gcc allow this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简单 2024-08-18 03:34:04

您可以包含任何您想命名的文件。

编辑:您也可以尝试一下。最坏的情况?你手上有一个“撤消”操作。

You can include any file you care to name.

EDIT: You could also have just tried it. Worst case? You have an "undo" on your hands.

痴骨ら 2024-08-18 03:34:04

不要忘记将您的各种项目包装在 #DEFINE 和 #IFDEF 中,以确保您不会到处重新定义垃圾,让编译器抱怨......

don't forget to wrap your various items in #DEFINE's and #IFDEF's to make sure you aren't redefining junk all over the place for your compiler to bitch about...

没企图 2024-08-18 03:34:04

正如克里斯所说,您可以包含任何您想命名的文件。

实际上,最好避免使用任意文件扩展名 - 我建议使用“SomeFile.inl”而不是“SomeFile.txt”,因为您选择的 IDE 在打开文件时更有可能对文件应用正确的语法突出显示。

As Chris says, you can include any file you care to name.

In practice it's best to avoid arbitrary file extensions - I'd suggest 'SomeFile.inl' over 'SomeFile.txt', as your IDE of choice is more likely to apply correct syntax highlighting to the file when you open it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文