#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++中的atoi 函数简介 2023-01-05
- 如何C++使用模板特化功能 2023-03-05
- 详解c# Emit技术 2023-03-25
- C语言基础全局变量与局部变量教程详解 2022-12-31
- C语言 structural body结构体详解用法 2022-12-06
- C++使用easyX库实现三星环绕效果流程详解 2023-06-26
- C利用语言实现数据结构之队列 2022-11-22
- C++详细实现完整图书管理功能 2023-04-04
- 一文带你了解C++中的字符替换方法 2023-07-20
- C/C++编程中const的使用详解 2023-03-26