转换preprocessor令牌字符串 [英] Convert a preprocessor token to a string
本文介绍了转换preprocessor令牌字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找一种方法来一个preprocessor令牌转换为字符串。
I'm looking for a way to convert a preprocessor token to a string.
具体来说,我在什么地方了:
Specifically, I've somewhere got:
#define MAX_LEN 16
和我想用它来prevent缓冲区溢出:
and I want to use it to prevent buffer overrun:
char val[MAX_LEN+1]; // room for \0
sscanf(buf, "%"MAX_LEN"s", val);
我打开其他的方法来完成同样的事情,但标准库而已。
I'm open to other ways to accomplish the same thing, but standard library only.
推荐答案
看<一个href=\"http://www.decompile.com/cpp/faq/file_and_line_error_string.htm\">http://www.decompile.com/cpp/faq/file_and_line_error_string.htm
具体做法是:
see http://www.decompile.com/cpp/faq/file_and_line_error_string.htm specifically:
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
#define AT __FILE__ ":" TOSTRING(__LINE__)
所以你的问题,可以通过执行来解决的sscanf(buf中,%的ToString(MAX_LEN)S,VAL);
这篇关于转换preprocessor令牌字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文