Fread Function Application

Source: Internet
Author: User

Header file: <cstdio/stdio. h>

Purpose:Reads data from a file stream.A maximum of Count elements can be read, with each element size byte. If the call is successful, the number of actually read elements is returned. If the call is unsuccessful or the file is read, 0 is returned.

Function prototype:Size_t fread (void * buffer, size_t size, size_t count, file * Stream)

Resolution:

Buffer: memory address used to receive data

Size: the number of bytes to read and write, in bytes.

Count: Number of read/write requestsSizeByte data items,Each element isSizeBytes.

Stream: input stream

Returned value: Number of actually read Elements.If the returned value isCountDifferent,The end of the file or an error may occur..

SlaveFerrorAndFeofGet error information or check whether it reaches the end of the file.

Example

Long long;

Fread (& A, sizeof (long), 1, STD );

Char B [10];

Fread (B, sizeof (char), 10, STD );

Question application:

Uvalive 6426-count:

Link: https://icpcarchive.ecs.baylor.edu/index.php? Option = com_onlinejudge & Itemid = 8 & page = show_problem & problem = 4437

The question says that the data is read from the binary stream, and the data volume reaches 10000*10000. With scanf, the input plug-in times out, and the input with fread does not time out.

Code:

# Include <iostream> # include <cstdio> # include <algorithm> # include <vector> # include <cstring> using namespace STD; int M, N; int A [10005] [10005]; int main () {int C; fread (& N, sizeof (INT), 1, stdin); fread (& M, sizeof (INT), 1, stdin); For (INT I = 0; I <n; I ++) {fread (A [I], sizeof (INT), m, stdin) ;}int L, R; int last = m; while (fread (& L, sizeof (INT), 1, stdin) {fread (& R, sizeof (INT), 1, stdin); int ans = 0; For (INT I = 0; I <n; I ++) {if (a [I] [0]> r) break; int LL = lower_bound (A [I], a [I] + Last, L)-A [I]; int RR = upper_bound (A [I], a [I] + Last, R)-A [I]; If (RR <= ll) continue; ans + = Rr-ll;} printf ("% d \ n", ANS);} return 0 ;}


Fread Function Application

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.