Why can’t I return std::getline’s as-if-boolean result?

The boolean conversion operator for std::basic_istream is explicit. This means that instances of the type will not implicitly become a bool but can be converted to one explicitly, for instance by typing bool(infile). Explicit boolean conversion operators are considered for conditional statements, i.e. the expression parts of if, while etc. More info about contextual conversions … Read more

adding booleans (as integer) [duplicate]

Try using IEnumerable<T>.Count(Func<T,bool>) from System.Linq, with T as bool, on a params method parameter. public static int CountTrue(params bool[] args) { return args.Count(t => t); } Usage // The count will be 3 int count = CountTrue(false, true, false, true, true); You can also introduce a this extension method: public static int TrueCount(this bool[] array) … Read more