Calculate code run time:
Count_seconds (T1)
//Middle code
count_seconds (T2) Time
: = T2-t1
Text manipulation:
Open_file () to open a file with three parameters:
Open_file (:: FileName, Filetype:filehandle)
The first parameter is the path and name of the file, and the third is a handle to the file, which is well understood by both parameters.
The second parameter is the file type, the official name is called FileType (feeling the name is not intuitive, rather than called OpenType), is actually deciding how to open the file. There are several options:
' input ':
An already existing input file was opened for reading in ASCII format.
Open a file that already exists and read it in ASCII format. This means that the file needs to exist under the path, and that the type is not writable and can only be read.
' Output ':
A new output file is opened for writing in ASCII format.
Opens a new file that is written in ASCII format. A file will be created when it does not exist.
' Append ':
An already existing output file was opened at the end of the file for writing in ASCII format.
An existing output file is opened at the end of the file and written in ASCII format. Writes at the end of an already existing file and does not create a new file.
' input_binary ':
An already existing input file was opened for reading in binary format.
' output_binary ':
A new output file is opened for writing in binary format.
' append_binary ':
An already existing output file was opened at the end of the file for writing in binary format.
The next three differs from the previous write format, with the first three being the ASCII format and the second three being binary.
fwrite_string () is used to write to a file that contains 2 parameters:
Fwrite_string (:: FileHandle, String:)
The first parameter is the output of open_file (), the second argument is the string to be written,
We can look at the examples given by the authorities;
Fwrite_string (filehandle,[' Text with numbers: ', 5, ' and ', 1.0])
The output is:
Text with Numbers:5 and 1.00000
When the content to be output is not a single string, number, or variable, use [] surround, the rest of the output stream with C + + has a similar place, the string plus ", the string and the variable or number is distinguished", "just in C + + we use the stream operator <<."
Fnew_line (filehandle) for line break
As an example:
Open_file (' f:/statistics. txt ', ' output ', filehandle)
fwrite_string (filehandle, ' variable 1: ')
fwrite_string (FileHandle, Angle)
fnew_line (FileHandle)