std::fread
Da cppreference.com.
![]() |
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate.
La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
Elemento definito nell'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.
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.
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.
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.
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.
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.
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) | |
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) | |
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) | |
C documentation for fread
|