本文介绍了良好的流状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在TC ++ PL3中,在21.3.3中,提供了以下ios_base定义:


class ios_base {

public:

// ...


typedef implementation_defined2 iostate;

static const iostate badbit,// stream is corrupted

eofbit,//看到文件结尾

failbit,//下一步操作将失败

== goodbit; // goodbit == 0


// ...

};

什么是goodbit == 0究竟是什么意思?

In TC++PL3, in 21.3.3, the following definition of ios_base is provided:

class ios_base{
public:
// ...

typedef implementation_defined2 iostate;
static const iostate badbit, // stream is corrupted
eofbit, // end-of-file seen
failbit, // next operation will fail
== goodbit; // goodbit==0

// ...
};
What does "goodbit==0" exactly mean?

推荐答案



字面意思是一切都好。 ''goodbit''没有设置位,因此

表示IO状态没有错误。

Means literally that everything is ok. ''goodbit'' has no bits set and therefore
means that the IO state is not in error.




这意味着ios_base :: goodbit的值为0.


iostate类型是一个位掩码(这意味着它是一个整数,

枚举或bitset)并且存在一个名为

goodbit的常量,值为0.


如果我是你,我会给自己一份标准或接近

标准的草稿。


-

Erik Wikstr?m

It means that ios_base::goodbit has the value 0.

The iostate type is a bitmask (which means that it is an integer,
enumeration or a bitset) and there exists a constant of this type named
goodbit with the value 0.

If I were you I''d get myself a copy of the standard or a draft close to
the standard.

--
Erik Wikstr?m




字面意思是一切都好。 ''goodbit''没有设置位,因此

意味着IO状态没有错误。


Means literally that everything is ok. ''goodbit'' has no bits set and therefore
means that the IO state is not in error.



这是让我问的0。在所有系统上,当goodbit的值为0时,是否保证

good()为真?还有

这适用于其余的iostates,badbit,eofbit和failbit,

OK设置值是0?

所以,我们可以只使用它的风格:

#include< iostream>


void iocopy()

{

使用命名空间std;


char c;


while(!cin.goodbit)

{

cin.get(c);

cout<< c;

} [john @ localhost src]


It is the 0 that made me asking. Does it mean that it is guaranteed that
good() is true when goodbit has the value 0, on all systems? Also does
this apply to the rest iostates, badbit, eofbit, and failbit, that the
OK setting is the value 0?
So, can we just use it in the style:
#include <iostream>

void iocopy()
{
using namespace std;

char c;

while(!cin.goodbit)
{
cin.get(c);
cout<< c;
}[john@localhost src]


这篇关于良好的流状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 22:40