在哪里/如何定义null?

Dav*_*e C 0 c++ null

Null没有宣布?

我的代码:

// Include necessary libraries
#include <cstdlib> // Exits
#include <iostream> // I/O
#include <cstring> // String functions
using namespace std;

int main(int argc, char *argv[])
{
    //Declare local Constants and Variables
    const char SOKINP[19] = "23456789TtJjQqKkAa"; // Valid Input Characters
    char acCards [5]; // Array to hold up to five cards (user input)
    bool bErr;        // Loop on Error (Calculated)
    int  i,           // Loop variable (Calculated)
    iNbrCrd,          // Number of Cards 2-5 (user input)
    iNAces,           // Number of Aces (Calculated)
    iTS;              // Total Score (Calculated)

    ...

    for (i=0;i<iNbrCrd;i++){
       do {
           cout << "Enter Card #" << i << " (2-9,t,j,q,k or a)  >";
           cin  >> acCards[i];
           cout << endl;
           bErr = (strchr(SOKINP, acCards[i]) == null) ? true : false; // *ERROR*
       } while (bErr);
    }
    return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)

[错误]'null'未在此范围内声明

我如何声明'null'?我试过包括其他几个库.我正在使用Dev C++ v5.4.2

谢谢,~d

The*_*ark 6

不是null.这是NULL全部大写.如果写入NULL不起作用,您可以使用自己定义

#define NULL 0
Run Code Online (Sandbox Code Playgroud)

  • @ValekHalfHeart当你将它定义为`(void*)0`时,你会得到完全**的类型不匹配警告**.在C和C++中,`0`是**任何类型**的空指针的有效文字,但是`(void*)0`仅适用于指向`void`的指针,因为C++中有严格的强类型.因此,`(void*)0`在C中比在'0'更安全,但在C++中它是错误的**. (6认同)