| | | | | |

Simple I/O Manipulators

  • Use
  • unsigned long y;
    std::cout << std::hex << y;  // output y in hex notation
    
  • Implementations
  • namespace std {
      // overload of operator <<() -- done in iostream library
      ostream& operator << (ostream& s, ios_base& F(ios_base&))
                      //  signature of a function - "function pointer"
      {
        return F(s);
      }
    
      // the manipulator function - clears basefield, then sets hex
      ios_base& hex (ios_base& s)
      {
        s.setf(ios_base::hex, ios_base::basefield);
        return s;
      }
    }
    

| | Top of Page | 5. Function Classes & - 7 of 11