Namespace
Varianti

std::fread

Da cppreference.com.
< cpp‎ | io‎ | c

 
 
Ingresso / libreria di output
I / O manipolatori
C-style I / O
Buffer
Original:
Buffers
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_streambuf
basic_filebuf
basic_stringbuf
strstreambuf(deprecato)
Streams
Original:
Streams
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Astrazioni
Original:
Abstractions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ios_base
basic_ios
basic_istream
basic_ostream
basic_iostream
File I / O
Original:
File I/O
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_ifstream
basic_ofstream
basic_fstream
String I / O
Original:
String I/O
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
basic_istringstream
basic_ostringstream
basic_stringstream
Array I / O
Original:
Array I/O
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
istrstream(deprecato)
ostrstream(deprecato)
strstream(deprecato)
Tipi
Original:
Types
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
streamoff
streamsize
fpos
Errore categoria interfaccia
Original:
Error category interface
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
iostream_category(C++11)
io_errc(C++11)
 
C-style I / O
Funzioni
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Accesso ai file
Original:
File access
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Diretta input / output
Original:
Direct input/output
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
fread
fwrite
Ingresso formattato / uscita
Original:
Unformatted input/output
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Formattato di input / output
Original:
Formatted input/output
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
File di posizionamento
Original:
File positioning
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ftell
fgetpos
fseek
fsetpos
rewind
La gestione degli errori
Original:
Error handling
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
clearerr
feof
ferror
perror
Le operazioni sui file
Original:
Operations on files
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
remove
rename
tmpfile
tmpnam
 
Defined in header <cstdio>
std::size_t fread( void* buffer, std::size_t size, std::size_t count, std::FILE* stream );
Legge fino a oggetti count nel buffer matrice dal flusso di input dato stream come se chiamando il numero std::fgetc size volte per ogni oggetto, e memorizzare i risultati, nell'ordine ottenuto, nelle posizioni successive buffer, che viene reinterpretata come una matrice di unsigned char. L'indicatore di posizione di file per il flusso viene avanti del numero di caratteri letti.
Original:
Reads up to count objects into the array buffer from the given input stream stream as if by calling std::fgetc size times for each object, and storing the results, in the order obtained, into the successive positions of buffer, which is reinterpreted as an array of unsigned char. The file position indicator for the stream is advanced by the number of characters read.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se gli oggetti non sono TriviallyCopyable, il comportamento non è definito.
Original:
If the objects are not TriviallyCopyable, the behavior is undefined.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se si verifica un errore, il valore risultante dell'indicatore file di posizione per il flusso è
Original:
If an error occurs, the resulting value of the file position indicator for the stream is
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
indeterminato. Se un elemento di parziale viene letto, il suo valore è indeterminato
Original:
indeterminate. If a partial element is read, its value is indeterminate
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

Indice

[modifica] Parametri

buffer -
puntatore al primo oggetto nella matrice da leggere
Original:
pointer to the first object in the array to be read
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
size -
dimensione di ogni oggetto in byte
Original:
size of each object in bytes
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
count -
il numero degli oggetti da leggere
Original:
the number of the objects to be read
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica] Valore di ritorno

Numero di oggetti letti correttamente, che può essere inferiore a count in caso di errore o fine del file condizione si verifica.
Original:
Number of objects read successfully, which may be less than count if an error or end-of-file condition occurs.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Se size o count è pari a zero, fread restituisce zero e non esegue alcuna altra azione.
Original:
If size or count is zero, fread returns zero and performs no other action.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[modifica] Esempio

#include <iostream>
#include <cstdio>
#include <fstream>
#include <vector>
int main()
{
    // prepare file
    std::ofstream("test.txt") << 1 << ' ' << 2 << '\n';
    std::FILE* f = std::fopen("test.txt", "r");
 
    std::vector<char> buf(4); // char is trivally copyable
    std::fread(&buf[0], sizeof buf[0], buf.size(), f);
 
    for(char n : buf)
        std::cout << n;
 
    std::vector<std::string> buf2; // string is not trivially copyable
// this would result in undefined behavior
//    std::fread(&buf2[0], sizeof buf2[0], buf2.size(), f);
}

Output:

1 2

[modifica] Vedi anche

legge l'input formattato da stdin, un flusso di file o di un buffer
Original:
reads formatted input from stdin, a file stream or a buffer
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(funzione) [edit]
ottiene una stringa di caratteri da un flusso di file
Original:
gets a character string from a file stream
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(funzione) [edit]
scrive su un file
Original:
writes to a file
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

(funzione) [edit]
C documentation for fread