This is a created article in which the information may have evolved or changed.
Figure 1
Figure 2
From the comparison of Figure 1 and Figure 2 can be seen, figure 2 is less than the 15th line of the read operation, and then the result of the figure 2 code run, is all the Hello WORLDABCDEFG, the code of Figure 1 only from read after the ABCDEFG.
What is the reason?
Read-write pointers in which mischief! Each read and write operation starts at the pointer position.
In Figure 1, after the first read, the read-write pointer has run to the place of Hello Word, not in 0, so the second read results from this non-0 pointer after the beginning of reading, so the result is only the back of the ABCDEFG.
In Figure 2, the read operation is not performed at first, so the reading and writing pointers remain at 0, so the next read starts at 0. The result is the full Hello WORLDABCDEFG.
Figure 3
As you can see from Figure 3, using buf.string () This way you can see that there is no movement of the read pointer.
Figure 4
As you can see from Figure 4, the first print is Hello world and not Hello Worldhello world, because there is a read operation. The read pointer is moved.
The second time you print out Hello Worldhello world is because it was written again. Indicates that the Wtire write operation does not move the pointer, and read read does not move the pointer.
Figure 5
From the ReadByte () and Unreadbyte () operations in Figure 5, it is more clear to see the movement of the read and write pointers.