码迷,mamicode.com
首页 > 编程语言 > 详细

c/c++ 中include

时间:2015-03-13 00:19:13      阅读:225      评论:0      收藏:0      [点我收藏+]

标签:

之前 在学习c/c++ 时只会在文件最开始时候调用#include “file.h”或者 #include <file.h>来 调用头文件,其实include 还可以用来load 数据文件。

新建一个文件:hello.txt,其内容为"Hello world!!",

 技术分享

技术分享
然后将 这些字符所对应的asc 码数值写到hello.hex文件中

技术分享 

技术分享
写Testbed 测试:
#include <stdio.h>
#include <stdlib.h>
 
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
};
 
 

c/c++ 中include

标签:

原文地址:http://www.cnblogs.com/wucowboy/p/4334049.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!