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<

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

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

 

3COME考试频道为您精心整理,希望对您有所帮助,更多信息在http://www.reader8.net/exam/