比如你定义了一个常量
#define myvalue  1000
但是我想把myvalue转换成字符串打印出来~~
似乎有这样一个方法,可以将任何的变量名,通过一个宏,直接转换成字符串~~
比如int
假设宏为#
就可以CString str = #int
cout<<str;
输出结果就是字符串:int

解决方案 »

  1.   

    构串操作符#只能修饰带参数的宏和行参,它将实参的字符序列(而不是实参代表的值)转换成字符串常量:#define STRING(x) #xint x = 30;
    char c='a';
    STRING(x);
    STRING(c);
      

  2.   

    #include<iostream>
    #include<string>
    #include<sstream>
    using namespace std;
    string itos(int i) // 将int 转换成string
    {
    stringstream s;
    s << i;
    return s.str();
    }这个???????还是sprintf???
      

  3.   

    #define myvalue  1000char aa[20];sprintf(aa,"%d",myvalue  )
    cout<<aa;