August 2012
Intermediate to advanced
976 pages
30h 17m
English
The logical NOT operator (!) returns the inverse of the truth value of its operand. We first used this operator in § 3.2.2 (p. 87). As another example, assuming vec is a vector of ints, we might use the logical NOT operator to see whether vec has elements by negating the value returned by empty:
// print the first element in vec if there is oneif (!vec.empty()) cout << vec[0];
The subexpression
!vec.empty()
evaluates as true if the call to empty returns false.
Read now
Unlock full access