Namensräume
Varianten
Aktionen

std::fread

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

 
 
Input / Output-Bibliothek
I / O-Manipulatoren
C-style I / O
Puffern
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(veraltet)
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.
Abstraktionen
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
Datei-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(veraltet)
ostrstream(veraltet)
strstream(veraltet)
Types
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
Fehler Kategorie Schnittstelle
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
Funktionen
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Dateizugriff
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.
Direkte Eingabe / Ausgabe
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
Unformatierte Eingang / Ausgang
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.
Formatierte Eingabe / Ausgabe
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.
Datei Positionierung
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
Fehlerbehandlung
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
Operationen auf Dateien
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 );
Liest bis zu count Gegenstände in dem Array buffer von dem gegebenen Eingabestrom stream wie durch calling std::fgetc size Zeiten für jedes Objekt, und Speicherung der Ergebnisse in der Reihenfolge erhalten wurde, in die aufeinanderfolgenden Positionen buffer, die als ein Array von interpretiert wird unsigned char. Die Datei Stellungsanzeige für den Strom wird durch die Anzahl der gelesenen Zeichen vorgeschoben .
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.
Wenn die Objekte nicht TriviallyCopyable, ist das Verhalten undefiniert .
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.
Wenn ein Fehler auftritt, ist der resultierende Wert der Dateipositionszeigers für den Strom
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.
unbestimmt. Wenn ein Teilelement gelesen wird, ist sein Wert unbestimmt
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.

Inhaltsverzeichnis

[Bearbeiten] Parameter

buffer -
Zeiger auf das erste Objekt in dem Array zu lesen
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 -
Größe jedes Objekts in Bytes
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 -
die Anzahl der Objekte zu lesen
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.

[Bearbeiten] Rückgabewert

Anzahl der Objekte erfolgreich gelesen, was weniger sein kann als count wenn ein Fehler oder End-of-File-Bedingung auftritt .
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.
Wenn size oder count Null ist, gibt fread Null und führt keine weitere Aktion .
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.

[Bearbeiten] Beispiel

#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

[Bearbeiten] Siehe auch

liest formatierten Eingaben von stdin, eine Datei-Strom oder einen Puffer
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.

(Funktion) [edit]
erhält eine Zeichenkette aus einem Datei-Stream
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.

(Funktion) [edit]
eine Datei schreibt
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.

(Funktion) [edit]
C documentation for fread