我有以下代码,我不确定它应该是== 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
,但我不确定?
答案 0 :(得分:3)
返回值仅记录为0表示失败或非零表示成功。
是的,你可以使用!= FALSE
或者你可以使用:
bool has_console = ::AttachConsole(ATTACH_PARENT_PROCESS);
从BOOL(实际为整数)到bool
的转换会将0转换为false
,将其他任何转换为true
- 正是您想要的。