std::fread
De cppreference.com
|
|
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
<metanoindex/>
<tbody> </tbody>| Déclaré dans l'en-tête <cstdio>
|
||
std::size_t fread( void* buffer, std::size_t size, std::size_t count, std::FILE* stream ); |
||
Lit jusqu'à
count objets dans le tableau buffer à partir du courant d'entrée donné stream comme par appel std::fgetc size fois pour chaque objet, et mémoriser les résultats, dans l'ordre obtenu, dans les positions successives de buffer, qui est réinterprété comme un tableau d' unsigned char. L'indicateur de position de fichier pour le flux avance du nombre de caractères lus .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.
Si les objets ne sont pas
TriviallyCopyable, le comportement est indéfini .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.
Si une erreur se produit, la valeur résultante de l'indicateur de position du flux est
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.
indéterminée. Si un élément partiel est lu, sa valeur est indéterminée
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.
Paramètres
| buffer | - | pointeur vers le premier objet dans le tableau doivent être lues
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 | - | taille de chaque objet en octets
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 | - | le nombre d'objets à lire
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. |
Retourne la valeur
Nombre d'objets lus avec succès, ce qui peut être inférieure à
count si une condition d'erreur ou de fin de fichier est atteinte . 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.
Si
size ou count est égal à zéro, fread renvoie zéro et n'effectue aucune autre action .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.
Exemple
#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);
}
Résultat :
1 2
Voir aussi
lit l'entrée en forme à partir stdin, un flux de fichier ou un tampon 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. (fonction) | |
reçoit une chaîne de caractères à partir d'un flux de fichier 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. (fonction) | |
écrit dans un fichier 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. (fonction) | |
C documentation for fread
|