I have a question on the standard behavior of calling tellp
on an empty ostringstream
. I have a function foo which calls tellp
the first thing:
void foo(std::ostream& os)
{
std::ostream::pos_type pos = os.tellp();
// do some stuff.
}
int main()
{
std::ostringstream os;
foo(os);
}
In Visual Studio 2005, calling this function with a newly created and empty ostringstream
results in the pos
variable to be set to an invalid pos_type
, which in Visual Studio 2005 is set to pos_type(_BADOFF)
.
ofstream
does not have the same behavior, where tellp
returns pos_type(0)
, which is a valid pos_type
.
Is this standard conforming behavior? Is this behavior consistent with other compilers?