比如,
long k;

MessageBox(NULL,"",k,MB_OK);<----这样显然会出错
那如何显示?

解决方案 »

  1.   

    long k;
    CString s;
    s.format("%l",k);
    MessageBox(NULL,"",s,MB_OK);
      

  2.   

    谢谢楼上的,不过我还是遇到一些麻烦,不知道你能不能帮我:我建的是一个Win32 App,通过查资料我知道CString需要用到MFC
    因此:
    #include "stdafx.h"
    #include "afxwin.h"
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
       long k=100;
       CString s;
       s.format("%l",k);
       MessageBox(NULL,"",s,MB_OK);
    }结果出错:
    #ifdef _WINDOWS_
    #error WINDOWS.H already included.  MFC apps must not #include <windows.h>
    #endif而代码中我并没有包含"windows.h"
      

  3.   

    这样再试试看 
      long k=100;
       char s[10];
       itoa(s,k,10);
       MessageBox(NULL,"",s,MB_OK);
      

  4.   

    应为
    long k=100;
    char s[10];
    itoa(k,s,10);
    ::MessageBox(NULL,"",s,MB_OK);
      

  5.   

    谢谢楼上各位!
    最后解决办法(lingfeng8888(棱枫)) :#include "stdafx.h"
    #include "stdlib.h"
    int APIENTRY WinMain(HINSTANCE hInstance,
                         HINSTANCE hPrevInstance,
                         LPSTR     lpCmdLine,
                         int       nCmdShow)
    {
    long k=100;
    char s[10];
    itoa(k,s,10);
    MessageBox(NULL,s,"",MB_OK);
    return 0;
    }另外有几个问题请教大家:
    1)我使用CString时候(参照第4贴)为什么会出现错误?
    2)carbon107(&lt;软件开发思想.h&gt;) 朋友说的
      ::MessageBox(NULL,"",s,MB_OK);
      和没有::有什么区别?我试了一下,两种方法都可以。
      什么时候应该使用::而什么时候不需要呢?