Search code examples
c++istreamsetstate

How many parameters does ios::setstate actually take?


Every definition I've seen of function ios::setstate( iostate state ) shows that the function takes ONE and ONLY ONE parameter yet when I compile a program with the following function call, everything compiles and runs just fine:

mystream.setstate( std::ios_base::badbit, true );

What exactly is the second parameter and why is there no documentation about it?

EDIT: I'm using the command line compiler of the latest version of Microsoft Visual Studio 2010.


Solution

  • It's required to accept a single argument, as you've noted, but implementations are allowed to extend member functions via parameters with default values (§17.6.5.5). In other words, as long as this works:

    mystream.setstate( std::ios_base::badbit );
    

    your compiler is conforming. Nothing says that your code doesn't have to work, though.

    (Your library implementation has decided that a boolean parameter would be useful to have. You never notice it because it has a default value, but you can still get into implementation-specific territory and provide the argument yourself. Whether or not this is a good idea is obviously another question, but probably not.)