(C++) operator!
January 7, 2018 · View on GitHub
(C++) operator!
operator! (pronounced 'logical not operator') is an operator to do a logical not on a boolean. In other words: !true is false, and !false is true.
The example code below asserts that a std::string is not empty, before returning the first character of it.
#include <cassert> #include <string> char GetFirstChar(const std::string& s) { assert(!s.empty()); return s[0]; } int main() { assert(GetFirstChar("Bilderbikkel")=='B'); }