4

我正在使用 opencv 读取和写入我的应用程序配置文件。我有一个我想存储在那里的布尔值。它保存为 int:

相机:自动增益:1

我尝试通过以下方式阅读它:

auto_gain=static_cast<bool>(static_cast<int>(camera["auto_gain"]));

但我收到警告:

警告 C4800: 'int' : 强制值为 bool 'true' 或 'false' (性能警告)

在这种情况下解析 bool 的正确方法是什么?

4

1 回答 1

4

正如在这个问题中所讨论的,您应该使用:

auto_gain = static_cast<int>(camera["auto_gain"]) != 0;
于 2012-12-19T11:18:48.360 回答