如何编写内联包含
How to write an inline include
我知道在Java中下面的两个代码示例做同样的事情,我想知道是否有可能在c++中做类似的事情。
// At the top
import System.out.println;
// In a function
println(" :) ");
和
// Directly in a function
System.out.println(" :) ");
例如,在c++中,我想把这个变成:
#include<time.h>
int main ()
{
clock_t started;
变成这样:
int main ()
{
(time.h)::clock_t started;
这在c++中可能吗?如果有,谁能举个例子?
不,这不可能。#include
指令由称为预处理器的单独"实体"处理,虽然它不是一个单独的程序,但它是编译器的不同组件,在编译代码之前"运行",并处理宏,#pragma
等。它没有模块的概念
源文件边界在c++中并不重要——一个特定的声明出现在某个文件中没有任何意义。
您可能正在寻找名称空间。
相关文章:
- 函数何时会在c++中包含stack_Unwind_Resume调用
- 如何为包含头文件的目标编写生成文件?
- 如何编写一个错误结构,该结构可以包含不同的强键枚举作为错误代码
- 为什么我可以在不链接任何额外库的情况下包含 sys/*.h
- 如何将另一个项目中用 C 编写的源代码包含在我自己的项目中,C++在 Visual Studio 中
- 如何为字符串编写正则表达式,其中包含一个数字至少一个数字,并且不包含任何字母
- 如何在C 中编写一个程序,以说明不知道它正在阅读的数据文本文件中包含多少行
- 字符 * 和字符串在C++中有何不同?(在描述中编写代码)
- 我如何编写一个脚本来创建.cpp文件,其中包含所有标题内容
- 如何为包含其他 protobuf 的 protobuf 文件编写文本
- 如何使用 sol2 编写包含 lua 表的文件
- 编写一个函数,返回一个堆栈,该堆栈包含所有小于给定数字的元素,并且顺序相同
- C++ - 如何编写和读取包含对象的结构?(写入和读取二进制文件)
- r语言 - 为什么当我使用 Rcpp 编写时,我不需要包含一些我应该以普通C++编写的库
- 是否可以在没有包含保护的情况下编写头文件,并且没有多个定义错误
- 当用c++编写数组时,我尝试将数组包含到另一个类中,但不起作用
- 在C#中为windows API编写COM服务器,从何开始
- 编写一个程序,输出包含5但不包含8的5位数的总数
- 编写一个程序,读取一串包含标点符号的字符,并写入被读取的内容,但删除了标点符号
- 如何编写内联包含