在VC++中为什么bool sss=TRUE 或bool sss=1 都会出错,难道一定要用BOOL吗?

解决方案 »

  1.   

    bool true false
    BOOL TRUE FALSEFALSE == false 都是0
    TRUE != true,  
    一个是1,一个是-1(FFFFFFFF)
      

  2.   

    我用
    bool sss=true 或bool=-1还是会出错啊!
    D:\VC++原代码\Chap03\HelloWin\Hellowin.c(64) : error C2065: 'bool' : undeclared identifier
    D:\VC++原代码\Chap03\HelloWin\Hellowin.c(64) : error C2146: syntax error : missing ';' before identifier 'dffdsf'
    D:\VC++原代码\Chap03\HelloWin\Hellowin.c(64) : error C2065: 'dffdsf' : undeclared identifier
    Error executing cl.exe.
      

  3.   

    不是bool有问题,是你的代码少了一个 分号 ;
      

  4.   

    HDC         hdc ;
         PAINTSTRUCT ps ;
         RECT        rect ;
         bool        dffdsf=-1 ;     switch (message)
         {
         case WM_CREATE:D:\VC++原代码\Chap03\HelloWin\Hellowin.c(64) : error C2065: 'bool' : undeclared identifier
    D:\VC++原代码\Chap03\HelloWin\Hellowin.c(64) : error C2146: syntax error : missing ';' before identifier 'dffdsf'
    D:\VC++原代码\Chap03\HelloWin\Hellowin.c(64) : error C2065: 'dffdsf' : undeclared identifier
    ================================================================CSDN 论坛助手 Ver 1.0 B0402提供下载。 改进了很多,功能完备!★  浏览帖子速度极快![建议系统使用ie5.5以上]。 ★  多种帖子实现界面。 
    ★  保存帖子到本地[html格式]★  监视您关注帖子的回复更新。
    ★  可以直接发贴、回复帖子★  采用XML接口,可以一次性显示4页帖子,同时支持自定义每次显示帖子数量。可以浏览历史记录! 
    ★  支持在线检测程序升级情况,可及时获得程序更新的信息。★★ 签名  ●  
         可以在您的每个帖子的后面自动加上一个自己设计的签名哟。Http://www.ChinaOK.net/csdn/csdn.zip
    Http://www.ChinaOK.net/csdn/csdn.rar
    Http://www.ChinaOK.net/csdn/csdn.exe    [自解压]
      

  5.   

    好象你不是用VC++写的代码,可能是UNIX下的代码,一种方法是加上VC++的头文件即#include <window.h>。另外是自己定义
    #define false 0 
    #define ture  1
      

  6.   

    全部代码如下,定义bool没什么特别的意义,只不过想试试!#include <windows.h>LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
                        PSTR szCmdLine, int iCmdShow)
    {
         static TCHAR szAppName[] = TEXT ("HelloWin") ;
         HWND         hwnd ;
         MSG          msg ;
         WNDCLASS     wndclass ;     wndclass.style         =  CS_HREDRAW |CS_VREDRAW ;
         wndclass.lpfnWndProc   = WndProc ;
         wndclass.cbClsExtra    = 0 ;
         wndclass.cbWndExtra    = 0 ;
         wndclass.hInstance     = hInstance ;
         wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
         wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
         wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
         wndclass.lpszMenuName  = NULL ;
         wndclass.lpszClassName = szAppName ;     if (!RegisterClass (&wndclass))
         {
              MessageBox (NULL, TEXT ("This program requires Windows NT!"), 
                          szAppName, MB_ICONERROR) ;
              return 0 ;
         }
         
         hwnd = CreateWindow (szAppName,                  // window class name
                              TEXT ("The Hello Program"), // window caption
                              WS_OVERLAPPEDWINDOW,        // window style
                              CW_USEDEFAULT,              // initial x position
                              CW_USEDEFAULT,              // initial y position
                              CW_USEDEFAULT,              // initial x size
                              CW_USEDEFAULT,              // initial y size
                              NULL,                       // parent window handle
                              NULL,                       // window menu handle
                              hInstance,                  // program instance handle
                              NULL) ;                     // creation parameters
         
         ShowWindow (hwnd, iCmdShow) ;
    //ShowWindow (hwnd, SW_SHOWMAXIMIZED) ;
      UpdateWindow (hwnd) ;
         
         while (GetMessage (&msg, NULL, 0, 0))
         {
              TranslateMessage (&msg) ;
              DispatchMessage (&msg) ;
         }
         return msg.wParam ;
    }LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
    {
         HDC         hdc ;
         PAINTSTRUCT ps ;
         RECT        rect ;
        bool        dffdsf=-1 ;     switch (message)
         {
         case WM_CREATE:
     if  (PlaySound (TEXT ("hellowin.wav"), NULL, SND_FILENAME | SND_ASYNC) ){
    //  MessageBox(hwnd,TEXT("DD"),TEXT("ss"),MB_OK);
     }
          //   ShowWindow(hwnd,SW_SHOWMAXIMIZED);
      return 0 ;
        case WM_SIZE:
    //MessageBox(hwnd,TEXT("DD"),TEXT("ss"),MB_OK);  
     return 0;
         case WM_PAINT:
            
     hdc = BeginPaint (hwnd, &ps) ;
              
              GetClientRect (hwnd, &rect) ;
              
              DrawText (hdc, TEXT ("Hello, Windows 98!"), -1, &rect,
                        DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
              
              EndPaint (hwnd, &ps) ;
          //   MessageBox(hwnd,TEXT("DD"),TEXT("ss"),MB_OK);
      return 0 ;
              
         case WM_DESTROY:
              PostQuitMessage (0) ;
              return 0 ;
         }
         return DefWindowProc (hwnd, message, wParam, lParam) ;
    }出错信息如下:
    --------------------Configuration: HelloWin - Win32 Debug--------------------
    Compiling...
    Hellowin.c
    D:\VC++原代码\Chap03\HelloWin\Hellowin.c(65) : error C2065: 'bool' : undeclared identifier
    D:\VC++原代码\Chap03\HelloWin\Hellowin.c(65) : error C2146: syntax error : missing ';' before identifier 'dffdsf'
    D:\VC++原代码\Chap03\HelloWin\Hellowin.c(65) : error C2065: 'dffdsf' : undeclared identifier
    Error executing cl.exe.HelloWin.exe - 3 error(s), 0 warning(s)
      

  7.   

    给人感觉bool是C++的东西,VC++好像是用BOOL的。
    毕竟两者还是有点区别的啊~~~
      

  8.   

    bool =0;other[false,true]
    BOOL 0,1[FALSE,TRUE]
      

  9.   

    好像Sdk用的是 C !
    没有 bool 这个数据类型吧!
      

  10.   

    bool是C++中的类型,有true和false
    BOOL是MFC中定义的:
      typedef int                 BOOL;
    其实BOOL是int型的数据,它有TRUE(1)和FALSE(0)两个值
      

  11.   

    把扩展名改成  .cpp 就可以了bool 是VC++的数据类型,标准C没有!