不想声明个变量,然后在转化 ,
int i=123;
CString str;
str.Format("%d",i); 
AfxMessageBox(str); //MessageBox 等都可以要写4行,这样很繁琐怎样在一两行实现这功能?int i=123;
AfxMessageBox(i); 

解决方案 »

  1.   

    如果不需要弹出窗口,在“输出”窗口显示的话
    TRACE("%d", i);
      

  2.   

    void MessageBoxInt(int i)
    {
       CString str;
       str.Format("%d",i);  
       AfxMessageBox(str); //MessageBox 等都可以
    }这样以后:
    int i=123;
    MessageBoxInt (i);  
      

  3.   

    自己造个全局的
    CString ShowInt(int i)
    {
      CString s;
      s.Format();
      return s;
    }
      

  4.   

    用宏.//定义
    #define AfxMessageBox(i) {CString str;str.Format("%d",i);AfxMessageBox(str);}  //使用
    int i=123;
    AfxMessageBox(i);  
      

  5.   

    稍完善下.//定义
    #ifdef _DEBUG
    #define AfxMessageBox_Debug(i) {CString str;str.Format("%d",i);AfxMessageBox(str);}
    #else
    #define AfxMessageBox_Debug(i) {}
    #endif//使用
    int i = 123;
    AfxMessageBox_Debug(i);
    AfxMessageBox("Test");
      

  6.   

      
    AfxMessageBox("123"); 这样行吧,我可没试过,不行别骂啊
      

  7.   

    TRACE("%d", i);嗯,还有就是楼上的同学们所说的。
      

  8.   

    lz其实函数也是一样的呀.而且函数比较稳定.#ifdef _DEBUG
    void MessageBoxInt(int i){CString str;str.Format("%d",i);AfxMessageBox(str);}
    #else
    void MessageBoxInt(int i){}
    #endif