Espaços nominais
Variantes
Acções

std::fread

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

 
 
De entrada / saída da biblioteca
I / O manipuladores
C estilo de I / O
Buffers
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(obsoleta)
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.
Abstrações
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
Cordas 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
Matriz de 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(obsoleta)
ostrstream(obsoleta)
strstream(obsoleta)
Tipos
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
Interface de categoria de erro
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 estilo de I / O
Funções
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Arquivo de acesso
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.
Directa de entrada / saída
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
Não formatado entrada / saída
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.
Formatado de entrada / saída
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.
Arquivo de posicionamento
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
De tratamento de erros
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
Operações em arquivos
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 );
Lê-se a objetos count no buffer matriz do fluxo de entrada dada stream como se chamando std::fgetc size vezes para cada objeto, e armazenando os resultados, na ordem obtida, para as posições sucessivas de buffer, que é reinterpretado como uma matriz de unsigned char. O indicador de posição de arquivo do fluxo é avançada pelo número de caracteres lidos.
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 os objetos não são TriviallyCopyable, o comportamento é indefinido.
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 ocorrer um erro, o valor resultante do indicador de posição de arquivo do fluxo é
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.
indeterminado. Se um elemento parcial é lido, o seu valor é indeterminado
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.

Índice

[editar] Parâmetros

buffer -
ponteiro para o primeiro objeto na matriz para ser lido
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 -
tamanho de cada objeto em 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 -
o número de objetos a serem lidos
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.

[editar] Valor de retorno

Número de objetos lido com sucesso, o que pode ser inferior a count se uma condição de erro ou de fim-de-arquivo ocorre.
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 ou count é zero, fread retorna zero e não executa nenhuma outra ação.
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.

[editar] Exemplo

#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

[editar] Veja também

lê entrada formatada de stdin, um fluxo de arquivo ou um tampão
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.

(função) [edit]
recebe uma cadeia de caracteres a partir de um fluxo de arquivo
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.

(função) [edit]
grava em um arquivo
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.

(função) [edit]
C documentation for fread