【发布时间】:2013-09-29 04:41:16
【问题描述】:
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;
}
[错误] 'null' 未在此范围内声明
如何声明“null”?我尝试包括其他几个库。 我正在使用 Dev C++ v5.4.2
谢谢,~d
【问题讨论】:
-
使用
NULL或nullptr。 -
@ta.speot.is:你应该说:使用
nullptr(或NULL)。顺序强调,强调很重要。 -
@ta.speot.is 在这种情况下,你应该说:“不要使用 Dev-C++,而是使用好的 C++ 编译器,使用
nullptr”。 -
@CareyGregory: this topic 给出了很多这样的例子。查看每个答案。
-
@Nawaz +1。重载示例令人信服。