当前位置导航:炫浪网>>网络学院>>编程开发>>C++教程>>C++进阶与实例

有趣的#define的一个实例

    看了一下google CoverStory的代码,有一个地方很有意思:

 // These are the various document types used by CoverStory.

// Included in both Obj-C and plist sources.

// A little magic to get CPP to turn things into cstrings for the code but have

// the strings raw for the plists. The reason we need this is if we just put

// them in quotes (cstrings) then we'd get those quotes in the plists, which we

// don't want.

#define STRINGIFY(x) #x

#define TO_STRING(x) STRINGIFY(x)

#define kGCOVTypeNameRaw GNU Compiler Coverage File

#define kGCOVTypeName TO_STRING(kGCOVTypeNameRaw)

    然后在使用的地方

    NSLog(@kGCOVTypeName);

    或者

    std::cout<<kGCOVTypeName;

    就能把GNU Compiler Coverage File值输出来了,

    但如果用NSLog(@#kGCOVTypeNameRaw);则不行。

相关内容
赞助商链接