tellp我对调用empty的标准行为有疑问ostringstream。我有一个函数 foo 调用tellp第一件事:
void foo(std::ostream& os)
{
std::ostream::pos_type pos = os.tellp();
// do some stuff.
}
int main()
{
std::ostringstream os;
foo(os);
}
在 Visual Studio 2005 中,使用新创建的空函数调用此函数ostringstream会导致pos变量设置为 invalid pos_type,而在 Visual Studio 2005 中设置为pos_type(_BADOFF)。
ofstream没有相同的行为,其中tellp返回pos_type(0),这是一个有效的pos_type。
这个标准符合行为吗?这种行为与其他编译器一致吗?