C ++ cow brush off questions day21

Explain some of the basic functions of 1 C ++ file operations:

fseek:

fseek function is used to set the current write location of the file.

Function Prototype: int fseek (FILE * fp, long offset, int origin);

Function: the write position pointer fp file to the specified location.

fseek (fp, 20, SEEK_SET) ; means that the position pointer fp file read and write the file starts moving from the 20 bytes.
ftell:

ftell function is used to get the current file position to read and write;

Function prototype: long ftell (FILE * fp)

Function: to give streaming file read current position, the return value is the number of bytes offset from the current file position to read and write head.

fgetc:

int fgetc(FILE *stream)
Reads a character from the file stream and returns. The successful return of characters read; read the end of the file or failed to return -1.
char *fgets(char *str,int length,FILE *fp)
Fp from the file pointed to by the read up to length-1 characters, str into the array is encountered \ n or EOF if the end of the read character before the length-1, i.e. the end of the reading, after the character string is read in Finally, add a '\ 0' character. Str pointer returns to normal, error, or encounters the end of the file, returns a NULL pointer.


int feof(FILE *stream)
Determining whether the end of the file is read, unread end returns 0, the end of the read returns non-zero. Generally do not, file read to the end, go read once, easily lead to read once. Not recommended for use!
int fread(void* buffer,int num,int count,FILE *fp)
int fwrite (void * buffer, int
num, int count, FILE * fp) the data pointed to by buffer write fp points to the file, data file, or the point fp in the read buffer, one for each NUM number of bytes of the write field, count the number of fields to be read. Returns the number of fields successfully read / write (count); return 0 errors or end of file. These two functions are different from other functions, when we tried to use fread / fwrite to read and write text files, I found the text format has no meaning, just an ordinary character. It is performed by a binary operation operation, it is popular for some text identifier such as '\ 0', '\ n ' is no longer sensitive to the other, when these are made into a textual identifier to a binary write . 
void rewind(FILE *STREAM)
Resets the file pointer to the beginning of a stream. 
2. instructions defaults stack variables
Stack space above the default local variables initialized to a random value.
 
Shaping global variables and static variables stati c shaping default initial value is 0.
Type of account the number of bytes 3.Turobo C

TURBO C in bytes for a variable of type int, not aligned

int 16-bit 2 bytes 4 bytes long int 32

4. Priority Queue

Common queue is a FIFO data structure, the end of the queue element is added, deleted from the queue head.

In the priority queue, the element is given priority. When accessing the element, the element with the highest priority is the first to be deleted. Priority queue with the most advanced, first-out (first in, largest out) the behavior characteristics.

 

The first to include the header file#include<queue> , he and queuedifferent is that we can customize where the priority of the data, so that a higher priority in the queue in front of priority from the team.

Queue priority queue has all the properties, including the basic operation of the queue, but this adds a sort on the basis of the internal, which is essentially a stack implemented.

The system calls and library calls

System call (system call) and library calls (Library functions): Under Linux, there are two ways of file operations. System call actually refers to the lowest level of a call in linux programming which is called the underlying meaning. Oriented hardware. The library function calls are then oriented application development, application of the equivalent api.
The answer is simple: library calls are part of the language or application, and system calls are part of the operating system.
Common file system function system
  1. fcntl document control  
  2. Open the file open  
  3. creat new file is created  
  4. close close the file descriptor  
  5. read file read  
  6. write write file  
  7. readv reads data from the file into the buffer array  
  8. writev the buffer array of data written to the file  
  9. pread file random read  
  10. pwrite file random write

6. scared, you can call the parent class virtual function subclass to achieve, I was shocked. So now it can be understood as long as a virtual declaration tells us not panic the first compiler, make sure that the parent and child class objects in the call. In other words, do not you ever order a static look upon.

If the parameter list of the function 7.printf number than the number of expressions, it will ignore the extra parameters later.

 

quest clear!

Guess you like

Origin www.cnblogs.com/Tonarinototoro/p/11575272.html