Search code examples
c++ostreammanipulators

How to put our own function declaration in iostream library in c++?


ostream& tab (ostream &o)
{
    return o << '\t';
}

I want to put this declaration in iostream library..how can i do this??


Solution

  • You can't. The contents of the iostream library are defined by the C++ standard, and potentially shared by every C++ program in the system. Although you can (in practice, this is technically forbidden by the standard) inject things into the std namespace for your own program (this is a bad idea however due to potential name collisions), and you can define things in your own libraries, you can't just go around modifying common libraries for everyone.