"C ++ Primer" reading note 4 (reproduced)

xiaoxiao2021-03-06  83

Note: 1.5

The content of this section is not very difficult, and those who have learned a programming will be easy, but I have always had a feeling. The most confused use of yourself is the I / O system, it is clear that I / O achieve direct operation of computer equipment. In C we know that it is done through the object of the iOS class. From the feeling, it is not as direct and understands. Of course, the benefits of doing this are greatly simple, but unfortunately, this will cause a certain difficulties to give us a certain difficulties. Here I will ask yourself.

First, everyone knows that our IO operation is done by three objects. CIN, COUT, CERR. The author used the word "binding" when described, which is clearly perfectly docked by the abstract data type and the specific device. But my question is, from the idea of ​​ADT, these objects encapsulate a license? Provide those operations? How do these data and interfaces control the device? Obviously, it is difficult to answer these questions in our current knowledge. Even if it is a reasonable estimate, it is impossible, but this thinking helps us familiar with the design thinking, but think about it. Otherwise, I will misunderstand myself.

Second, there is a problem, beginners may ask, the author tells us that Cout and Cerr can be used. Their difference is a general output, one is output error message. But this explanation does not satisfy our curious people. So I did a prank, rewrived our well-known "Hello World!"

Int main () {

CERR << "Hello World!" << Endl;

Return 1;

}

It turns out that if the user does not look at the code. They won't know that they see is an ERR. Then the difference between the two objects is just a habit or agreement? We can also explain. Leave it, I believe that the "Enlink"

Third, I want to talk about the "endl", is it right than "/ n" in many textbooks? No, you can write down the following sentence.

COUT << "AAA";

a = getchar (); //. Assumption A already defined

Cout << a;

In VC6, you will find the order of input and output (just in VC . Net 2003) is normal, strange. Therefore, it is not recommended to use C in C ), why? Author tells us ENDL In addition to / N There is also a refresh function, what is refreshed? Look carefully, refresh the buffer. What is a buffer? Oh. This question may require some other knowledge, such as. Computer composition principle

Regarding the operation of the document, it is very similar to the single file. The only thing to pay attention to is the reference, memory? Or file?

On the end of the note, I still have to remind everyone. I propose a lot of horn tip. Just proposes some personal recommendations for beginners. Some of these problems itself has no discussion. Some are not the problem now. In this section, your task is actually very simple, find the role of each object and operator. That's it, the father of C will speak C to be difficult to use, and we can understand the meaning of this sentence. Be constantly think of this sentence,

forward from

http://blog.9cbs.net/owl2008/

转载请注明原文地址:https://www.9cbs.com/read-104930.html

New Post(0)