首页 > 其他 > 详细

C宏定义中的 #,##,#@

时间:2014-08-15 21:10:19      阅读:318      评论:0      收藏:0      [点我收藏+]
宏定义中会出现#xxx ,A###B,以及微软独自特有的#@xxx。分别解释。


1 define SB(x) #x
它的作用是把输入的东西转换为字符串
string str = SB(123);


2 define BB(x) UXX##x
这个是个符号连接的作用,把UXX(随意的跟符号x连接成一个新的符号,这里说的符号就是变量的意思
int BB(1);
U1 = 100;


3 define CB(x) #@x
作用会是把x的最后一个字符转换成字符,这个是Windows独有的。
char b = CB(14c2);

最最终的实例程序如下:
#include <iostream>
#include <fstream>
#include <string>
#include <stdio.h>
using namespace std;

#define H1 123

#define SB(x) #x	//translate to a string
#define BB(x) U##x  //produce a new symbol
#define CB(x) #@x	//make the last to a char

void main()
{
	int x = H1;
	//cout<<x<<endl;
	ofstream fout("1.txt");
	fout<<x<<endl;
	fout<<"1234"<<endl;


	fout.close();
	FILE* fp = fopen("2.txt","w");
	fwrite(&x,4,1,fp);
	fprintf(fp,"%d",x);
	fclose(fp);
	string str = SB(123);
	std::cout<<str<<endl;
	int BB(1);
	U1 = 100;
	cout<<U1<<endl;
	char b = CB(14c2);
}


C宏定义中的 #,##,#@,布布扣,bubuko.com

C宏定义中的 #,##,#@

原文:http://blog.csdn.net/ddupd/article/details/38590187

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!