be written. If you try to add an element after position reaches capacity, bufferoverflowexception is thrown.
Then the read operation is performed.
After writing, the next step is to read the buffer. Before reading data, you must call the flip method to complete read/write conversion.
After calling flip, limit = position, position = 0, mark =-1; you can see that this is ready for reading:ProgramIt can be read from position. The get method is used for reading. Each time an element is read,
next() { $this->currentBook++; } /** * (PHP 5 >= 5.0.0) * Return the key of the current element * @link http://php.net/manual/en/iterator.key.php * @return mixed scalar on success, or null on failure. */ public function key() { return $this->currentBook; } /** * (PHP 5 >= 5.0.0) * Checks if current position is valid * @link http://php.net/manual/en/iterator.valid.php * @return boolean The return value will be casted to boole
The code is as follows:
$file = new \SplFileObject($path->get(), 'w');$file->fwrite('UUUaaaaOA323423482739S');$file->rewind();echo $file->fgets();exit;
The results are as follows:
Data has been successfully written to the specified file
But Echo fgets () is an empty string.
Modify the code to remove the parameter ' W ' from the initial method, as follows:
$file = new \SplFileObject($path->get());$file->fwrite('----------UUUaaaaOA32342348
functions.
Fopen () Open stream
Fclose () Close the stream
Fputc () writes a character to the stream
Fgetc () reads a character from the stream
Fseek () locates the specified character in the stream
Fputs () writes a string to a stream
Fgets () reads a row or a specified character from the stream.
Fprintf () Outputs Data to the stream in the format
Fscanf () reads data from the stream in the format
Returns the true value when feof () reaches the end of a file.
Returns the v
() read a character from the stream fseek () locate the specified character in the stream fputs () write a string to the stream fgets () read one or more characters from the stream fprintf () output to the stream in the format fscanf () read from stream by format feof () returns the true value when it reaches the end of the file returns the value when an error occurs in ferror () rewind () reset the file locator to the beginning of the file
the end of the file is returned, is true, otherwise returns 0, whose prototype is int feof (file *stream);Example: if (feof (FP)) printf ("To End of file");11.ferror ()The prototype is an int ferror (file *stream), which returns the nearest error code for the stream, which can be cleared by Clearerr (), and Clearerr () is a void Clearerr (file *stream);Example: printf ("%d", Ferror (FP));12.rewind ()The current read and write position is returned to
Realized the deletion and modificationA struct was created to save Num name cout priceCode#include #include #include #include typedef struct{int num;Char name[32];int count;int price;}good;int main (int argc,char *argv[]){FILE *FP;Good good;Fp=fopen (Argv[1], "A +");if (NULL==FP){Perror ("Fopen1");return-1;}Fclose (FP);Fp=fopen (Argv[1], "r+");if (NULL==FP){Perror ("Fopen2");return-1;}int n;printf ("Please input your select function\n\n");printf ("----1-------------store good\n");printf ("----2-
(1) Rewind () function
This function sets the pointer of the file handle to the beginning of the file stream, with the following syntax:
BOOL Rewind (Resource handle)
(2) fseek () function
The Fseek () function implements the positioning of the file pointer with the following syntax:
int fseek (Resource handle,int offset[,int whence])
The handle parameter is the file to open
Offset to the pointer position
The Iterator interface, a predefined PHP interface, can iterate its own external Iterator or class interface internally.
Interface abstract
Iterator extends Traversable {/* method */abstract public mixed current (void) abstract public scalar key (void) abstract public void next (void) abstract public void rewind (void) abstract public boolean valid (void )}
Pre-defined iterator
PHP already provides some iterators for daily tasks, such as SPL iterator
Clear (): empties the buffer and returns a reference to the bufferBuffer Flip (): Sets the bounds of the buffer to the current position and reloads the current position to 0int capacity (): Returns the capacity size of BufferBoolean hasremaining (): Determines if there are elements in the bufferint limit (): Returns the position of the bounds (limit) of the BufferBuffer limit (int n): Sets the buffer bounds to n and returns a buffer object with a new limitBuffer Mark (): Sets the flag on the bu
The Code is as follows: {code ...} the result is as follows: the data has been successfully written to the specified file, but the echofgets () is a null string to modify the code. Remove the parameter #039; w #039; in the initial method, as shown below: {code ...} the result is as follows: Data Writing fails, but echofgets () can get the number of previously written data... the Code is as follows:
$file = new \SplFileObject($path->get(), 'w');$file->fwrite('UUUaaaaOA323423482739S');$file->
environments, dump is more comfortable to use personally.If there is a condition, dump can also store the backup on tape. Linux typically uses/DEV/ST0 to represent a rewind device, while a/dev/nst0 represents a non-rewind device that, when used with a rewind device, is automatically rewind and then stored when the tap
1, function.defprofit (volume, price,cost):Print("We sell%d ice cream a day."%volume)Print("You can buy a ice cream at the price of%d dollars"%Price )Print("Make an ice cream would cost us%d dollars."%Cost )Print("Then we daily profit can be%d dollars."% ((price-cost) *volume))Print("We can just give the function numbers directly:") Profit (500,20,10)Print("Or We can use the variables from our script:") Volume= 200 Price=10 Cost= 3profit (Volume,price,cost)Output Result:2, functions and files. f
What we will see in this article is the full user manual for the FLV Player 4 free Software!
Begin
Run your FLV or media files
Stop
Stop running your FLV or media files
Stay
Temporarily suspend running your FLV or media files. Press more continuously to play from the stay point
Rewind Belt
Rewind your FLV or media files/go back
Fast Forward
Submit your FLV or media file/continue
Pr
Forward and rewind buttons. Both of these technologies are encapsulated in a simple JavaScript library for the benefit of developers.
the problems that exist
Bookmarks and fallback buttons run smoothly on traditional, multiple-page Web applications. When users surf the web, their browser address bar updates the URL, which can be pasted into the email or added to the bookmark for later use. The fallback and forward buttons can also work
location of the file pointer read/writeCall: Int Ftell (Resource $handle) output: Returns the position of the file pointer specified by handle, which is the offset in the file stream138.fseek (): Locating in the file pointercalled: int fseek (resource $handle, int $offset [, int $whence]) output: Success returns 0; otherwise returns-1139.rewind (): Rewind the position of the file pointerCall: BOOL
First read and write to open (r+ w+ A + can, but note that the read and write position pointers point to the file header, file header, file end), reading one character at a time (at this point the reading and writing position pointer to this byte, after the judge, to convert, move the read and write position pointer
Fseek (Fp,-1l,seek_cur), then written, as stipulated in C: Open the file in the above three ways, both readable and writable, but without inserting the fseek () or
Random Read and write of files
The previous read and write to the file are sequential read and write, that is, read and write files can only start from scratch, in order to read and write the data. However, in practical problems, it is often required to read and write only a specified part of a file. To solve this problem, you can move the position pointer within the file to the location where you want to read and write, and then read and write, which is called Random Read and write. The key to
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.