4

I'm using opencv to read and write my app configuration file. I have a bool that i want to store there. It it saved as an int:

camera: auto_gain: 1

I try to read it the following way:

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

but I get a warning:

warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)

What is the correct way to parse bool in that case?

4gn3s
  • 218
  • 2
  • 9

1 Answers1

4

As discussed in this question, you should use:

auto_gain = static_cast<int>(camera["auto_gain"]) != 0;
Community
  • 1
  • 1
yiding
  • 3,482
  • 18
  • 17