我有以下代码,我不确定它应该是== TRUE还是!= FALSE。
这是现在的代码:
void AttachConsole() {
bool has_console = ::AttachConsole(ATTACH_PARENT_PROCESS) == TRUE;
if (!has_console) {
// We weren't launched from a console, so just return.
// We could alloc our own console, but meh:
// has_console = AllocConsole() == TRUE;
has_console_attached_ = false;
return;
}
has_console_attached_ = true;
}我认为应该是!= FALSE,但我不确定?
发布于 2017-07-08 09:20:38
仅将返回值记录为0(表示失败)或非0(表示成功)。
所以,是的,你可以使用!= FALSE,或者你可以直接使用:
bool has_console = ::AttachConsole(ATTACH_PARENT_PROCESS);从BOOL (实际上是一个整数)到bool的转换将把0转换成false,其他任何东西都会转换成true--这正是您想要的。
https://stackoverflow.com/questions/44981590
复制相似问题