#include anywhere(#包括任何地方)
问题描述
#include <file> 是仅用于标头,还是只是机械的在此处注入此代码",可以在代码中的任何位置使用?
Is the #include <file> meant to be used for headers only or is it simply a mechanical "inject this code here" that can be used anywhere in the code?
如果我在 cpp 函数的中间使用它来从单一来源注入"代码会怎样?这会奏效还是编译器会为此大喊大叫?
What if I use it in the middle of a cpp function to just "inject" code from a single source? will this work or will compilers scream about this?
推荐答案
它是一个机械的在此处注入代码设备.如果您愿意,可以包含一个包含歌德浮士德的文本文件.你可以把它放在任何地方,甚至在函数的中间(当然,#include 需要换行!).
It is a mechanical inject the code here device. You can include a text file containing Goethe's Faust if you wish to. You can put it anywhere, even in the middle of a function (of course, #include needs a fresh line!).
但是,仅对头文件使用 #include 是一种严格的约定.可能有一些我不会反对的原因,例如提取机器生成的代码或将所有翻译单元合并到一个文件中.
However, it's strong convention to only use #include for header files. There may be reasons where I wouldn't object on it, for example pulling in machine-generated code or merging all translation units in a single file.
这篇关于#包括任何地方的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:#包括任何地方
基础教程推荐
- C语言 详解字符串基础 2023-03-27
- C++实战之二进制数据处理与封装 2023-05-29
- [C语言]二叉搜索树 2023-09-07
- C语言编程C++旋转字符操作串示例详解 2022-11-20
- C++实现ETW进行进程变动监控详解 2023-05-15
- C语言实现宾馆管理系统课程设计 2023-03-13
- centos 7 vscode cmake 编译c++工程 2023-09-17
- [c语言-函数]不定量参数 2023-09-08
- 全面了解C语言 static 关键字 2023-03-26
- 带你深度走入C语言取整以及4种函数 2022-09-17
