converting a variable name to a string in C++

前端 未结 8 1029
广开言路
广开言路 2020-12-01 01:15

I\'d like to output some data to a file. For example assume I have two vectors of doubles:

vector data1(10);
vector data2(10); 
         


        
8条回答
  •  一个人的身影
    2020-12-01 02:01

    Slightly adapted from @sarnold's answer, for C++:

    #define DEBUG(x) std::cout << #x << " = " << x << std::endl;
    

    An example program which uses this:

    int main() {
        int foo = 1;
        DEBUG(foo);
    
        return 0;
    }
    

提交回复
热议问题