c毕业论文外文翻译(编辑修改稿)内容摘要:

ut is wcout。 and standard error is wcerr. Each of the IO headers defines both the char and wchar_t classes and standard input/output objects. The streambased wchar_t classes and objects are defined in iostream, the wide character file stream types in fstream, and the wide character string streams in sstream. No Copy or Assign f or IO Objects For reasons that will be more apparent when we study classes and inheritance in Parts III and IV, the library types do not allow allow copy or assignment. This requirement has two particularly important implications. As we39。 ll see in Chapter 9, only element types that support copy can be stored in vectors or other container types. Because we cannot copy stream objects, we cannot have a vector (or other container) that holds stream objects. The second implication is that we cannot have a parameter or return type that is one of the stream types. If we need to pass or return an IO object, it must be passed or returned as a pointer or reference. Typically, we pass a stream as a nonconst reference because we pass an IO object intending to read from it or write to it. Reading or writing an IO object changes its state, so the reference must be nonconst. . Condition States Before we explore the types defined in fstream and sstream, we need to understand a bit more about how the IO library manages its buffers and the state of a stream. Keep in mind that the material we cover in this section and the next applies equally to plain streams, file streams, or string streams. Inherent in doing IO is the fact that errors can occur. Some errors are recoverable。 others occur deep within the system and are beyond the scope of a program to correct. The IO library manages a set of condition state members that indicate whether a given IO object is in a usable state or has encountered a particular kind of error. The library also defines a set of functions and flags, listed in Table , that give us access to and let us manipulate the state of each stream. If we enter Borges on the standard input, then cin will be put in an error state following the unsuccessful attempt to read a string of characters as an int. Similarly, cin will be in an error state if we enter an endoffile. Had we entered 1024, then the read would be successful and cin would be in a good, nonerror state. To be used for input or output, a stream must be in a nonerror state. The easiest way to test whether a stream is okay is to test its truth value. The if directly tests the state of the stream. The while does so indirectly by testing the stream returned from the expression in the condition. If that input operation succeeds, then the condition tests true. Condition States Many programs need only know whether a stream is valid. Other programs need more finegrained access to and control of the state of the stream. Rather than knowing that the stream is in an error state, we might want to know what kind of error was encountered. For example, we might want to distinguish between reaching endoffile and encountering an error on the IO device. Each stream object contains a condition state member that is managed through the setstate and clear operations. This state member has type iostate, which is a machinedependent integral type defined by each iostream class. It is used as a collection of bits, much the way we used the int_quiz1 variable to represent test scores in the example in Section (p. 156). Each IO class also defines three const values of type iostate that represent particular bit patterns. These const values are used to indicate particular kinds of IO conditions. They can be used with the bitwise opera。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。