心渐渐失空

导航

C中变量名通过宏定义转换成char*类型字符串

#include <iostream>

#include <stdlib.h>

#define name_to_str(name)(#name)

int main()

{

  int sum = 10;

  std::cout<<name_to_str(sum)<<std::endl;//调用宏输出char*型“sum”

  system("pause");

  return 0;

}

posted on 2015-10-17 11:02  心渐渐失空  阅读(1182)  评论(0编辑  收藏  举报