如何使用netbeans for C ++为头文件中的空格实现退出语句? [英] How do I implement an exit statement for a blank space in header file using netbeans for C++ ?

查看:70
本文介绍了如何使用netbeans for C ++为头文件中的空格实现退出语句?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须为我的程序中的任何内容返回空白的退出语句。对于输入和声明的构造函数。香港专业教育学院尝试使用为空白和空,但都没有工作。我应该包含一个系统预处理器语句来使其工作吗?



我尝试过:



I have to make exit statements for anything in my program that comes back blank. For input and for constructors that are declared. Ive tried using "" for blank and "NULL" but neither work. Is there a system preprocessor statement I should be including to make this work?

What I have tried:

string PatientBillingInformation::getPatientDiagnosisCode()
{
	if(patientDiagnosisCode == "")
	{
	   cerr << "Missing input." << endl;
	   exit(4);
	}
	return patientDiagnosisCode;
}





我也试过:



and i've also tried:

string PatientBillingInformation::getPatientDiagnosisCode()
{
	if(patientDiagnosisCode == "NULL")
	{
	   cerr << "Missing input." << endl;
	   exit(4);
	}
	return patientDiagnosisCode;
}

推荐答案

您必须正确地将您的patientDiagnosisCode变量与值进行比较。这取决于您的patientDiagnosisCode对象类型或类。代码听起来像数字 !!!



也许检查为:



you must correctly compare your patientDiagnosisCode variable against the values. It depends on what your patientDiagnosisCode objects type or class. Code sounds like a number!!!

Maybe checks as:

if( (patientDiagnosisCode.length == 0) ||
(patientDiagnosisCode.IsEmpty())  ||
(patientDiagnosisCode == NULL) )//as values NOT as string is correct
{
//your error and exit strategy
}


字符串NULL并不代表 NULL ,你的代码应该是:

The string "NULL" does not mean NULL, your code should be:
string PatientBillingInformation::getPatientDiagnosisCode()
{
	if(patientDiagnosisCode == NULL)
	{
	   cerr << "Missing input." << endl;
	   exit(4);
	}
	return patientDiagnosisCode;
}



虽然以这种方式在函数中使用退出语句是非常糟糕的做法。最好返回所持有的任何值,并让调用者决定采取什么行动。


Although it is very bad practice to have exit statements within functions in this way. It is better to return whatever value is held, and let the caller decide what action to take.


这篇关于如何使用netbeans for C ++为头文件中的空格实现退出语句?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆