c/c++ 中include

2015-07-20 17:10:57 来源: 作者: 浏览: 2
之前 在学习c/c++ 时只会在文件最开始时候调用#include “file.h”或者 #include 来 调用头文件,其实include 还可以用来load 数据文件。
?
新建一个文件:hello.txt,其内容为"Hello world!!",
?
?
然后将 这些字符所对应的asc 码数值写到hello.hex文件中
?
?
写Testbed 测试:
#include
#include
?
char hex[] = {
?#include "hello.hex"
};
int main()
{
?printf("%s", hex);
?system("pause");
?return 0;
}
?
?
如果不转化成 asc码,如果想输出字符,把文件中的字符串加上“”即 "Hello World!!"。
?
看到这里,对include 有了更深刻更清晰的理解,它在编译之前进行预处理,是负责将其link 到的文件,导入到改文件中(头文件也一样),这么做的本质原因,是为了让高级语言更加好维护,结构更加清晰
?
char hex[] = {
?#include "hello.hex"
};
?
等同于
char hex[] = {
?0x48, 0x65, 0x6C, 0x6C, 0x6F, 0x20, 0x57, 0x6F, 0x72, 0x6C, 0x64, 0x21, 0x21, 0x0D, 0x0A
};
?
-->

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: