名前空間
変種
操作

std::fread

提供: cppreference.com
< cpp‎ | io‎ | c

 
 
入力/出力ライブラリ
I / Oのマニピュレータ
CスタイルのI / O
バッファ
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(廃止予定)
ストリーム
Original:
Streams
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
抽象化
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
ファイル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
文字列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
アレイの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(廃止予定)
ostrstream(廃止予定)
strstream(廃止予定)
タイプ
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
エラーカテゴリインターフェース
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スタイルのI / O
機能します
Original:
Functions
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
ファイルアクセス
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.
直接入力/出力
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
書式なし入力/出力
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.
書式付き入力/出力
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.
ファイル位置付け
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
エラー処理
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
ファイルに対する操作
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 );
の配列として解釈さcountbuffer各オブジェクトの倍、streamの連続した​​位置に、得られたために、結果を格納し、呼び出したかのようにstd::fgetc与えられた入力ストリームから配列sizebufferオブジェクトまで読み込みunsigned char。ストリームのファイル位置指示子は、読み込まれた文字数分だけ進みますが.
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.
オブジェクトがTriviallyCopyableされていない場合、動作は未定義です.
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.
エラーが発生した場合は、ストリームのファイル位置指示子の結果の値です
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.
不定。部分的な要素が読み込まれた場合、その値は不定です
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.

目次

[編集] パラメータ

buffer -
読み込まれる配列内の最初のオブジェクトへのポインタ
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 -
各オブジェクトのサイズ(バイト単位)
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 -
読み込まれるオブジェクトの数
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.

[編集] 値を返します

オブジェクトの数がエラーまたはファイルの終端に達した状態が発生した場合count未満であるかもしれない、正常に読み込ま.
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.
もしsizeまたはcountゼロで、freadはゼロを返し、他のアクションを実行しません.
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.

[編集]

#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

[編集] も参照してください

stdin、ファイルストリームまたはバッファからの書式付き入力を読み取ります
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.

(機能) [edit]
ファイルストリームから文字列を取得します
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.

(機能) [edit]
ファイルに書き込みます
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.

(機能) [edit]
C documentation for fread