In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
Today, I will talk to you about the introduction of the application function on how to operate C++ files, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following contents for you. I hope you can get something according to this article.
C++ programming language is applied flexibly and can be regarded as an upgraded version of C language. Through the relevant methods about the operation of C++ files introduced in this article, we can have a preliminary grasp of the relevant application skills of this computer programming language and deepen our understanding of the language.
1. Function function in file operation of Clipper +
Used to read and write a data block.
two。 General invocation form
Fread (buffer,size,count,fp)
Fwrite (buffer,size,count,fp)
3. Description
(1) buffer: it is a pointer, and for fread, it is the address where the read data is stored. For fwrite, the address to which the data is to be output.
(2) size: the number of bytes to read and write
(3) count: how many size bytes of data items to read and write
(4) fp: file pointer.
Note: 1 after completing the write operation (fwrite ()), you must close the stream (fclose ())
2 after completing a C++ file operation (fread ()), if the stream (fclose ()) is not closed, the pointer (FILE * fp) automatically moves backward the length of the previous read and write. If the stream is not closed for the next read operation, the output continues with the last output.
3 fprintf (): input to the stream in format, the prototype is int fprintf (FILE * stream, const char * format [, argument,...]); its usage is the same as printf (), but not to the console, but to the stream. Note that the return value is the number of bytes written to the file for this operation. For example, int c = fprintf (fp, "% s% s% d% f", str1,str2, a, b); str1:10 bytes; str2: 10 bytes; aRO 2 bytes; BRV 8 bytes, c is 33, because a space is automatically added between different data when writing.
The file must be closed after use, otherwise the content will not be displayed correctly. Fwrite: read in two student information and save the file with fwrite
Fread: use fread to read student information from the file.
Fwrite.c # include # define SIZE 2 struct student_type {char name [10]; int num; int age; char addr [10];} stud [SIZE]; void save () {FILE * fp; int i; if ((fp=fopen ("stu_list", "wb")) = = NULL) {printf ("cant open the file"); exit (0);} for
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.