码迷,mamicode.com
首页 > 其他好文 > 详细

将变量名变为字符串

时间:2016-07-21 23:35:14      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:

 

将变量名 变为字符串的方法,很神奇,今天刚发现

#include <iostream>
using namespace std;
#define _showMem(str,v) showMem(#str,v)
struct student
{
    string name;
    int age;
    char sex;
};
void showMem(const char * str,int v)
{
    cout<<str<<"  "<<v<<endl;
}
int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";
    student s1;
    s1.name = "lili";
    s1.age = 23;
    s1.sex = f;
    _showMem(student.age,s1.age);
    system("pause");
    return 0;
}

输出

技术分享

将变量名变为字符串

标签:

原文地址:http://www.cnblogs.com/techdreaming/p/5693338.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!