std:: fwrite
| I/O manipulators | ||||
| Print functions (C++23) | ||||
| C-style I/O | ||||
| Buffers | ||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(C++20)
|
||||
| Streams | ||||
| Abstractions | ||||
| File I/O | ||||
| String I/O | ||||
| Array I/O | ||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(C++23)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
|
(
C++98/26*
)
|
||||
| Synchronized Output | ||||
|
(C++20)
|
||||
| Types | ||||
| Error category interface | ||||
|
(C++11)
|
||||
|
(C++11)
|
| Types and objects | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Functions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<cstdio>
|
||
|
std::
size_t
fwrite
(
const
void
*
buffer,
std::
size_t
size,
std::
size_t
count,
std::
FILE
*
stream
)
;
|
||
최대 count 개의 이진 객체를 주어진 배열 buffer 에서 출력 스트림 stream 으로 기록합니다. 각 객체는 unsigned char 배열로 재해석되고, std::fputc 를 각 객체마다 size 회 호출하여 이러한 unsigned char 들을 순서대로 stream 에 기록하는 것처럼 작성됩니다. 스트림의 파일 위치 표시자는 기록된 문자 수만큼 전진합니다.
객체가 TriviallyCopyable 하지 않다면, 동작은 정의되지 않습니다.
오류가 발생하면 스트림의 파일 위치 지시자 결과 값은 불확정적입니다.
목차매개변수
반환값성공적으로 쓰여진 객체의 수로, 오류가 발생한 경우에만
예제
이 코드 실행
#include <array> #include <cstdio> #include <vector> int main () { // 버퍼를 파일에 쓰기 if (std::FILE* f1 = std::fopen("file.bin", "wb")) { std::array<int, 3> v = {42, -1, 7}; // std::array의 내부 저장소는 배열입니다 std::fwrite(v.data(), sizeof v[0], v.size(), f1); std::fclose(f1); } // 동일한 데이터를 읽어 표준 출력에 표시 if (std::FILE* f2 = std::fopen("file.bin", "rb")) { std::vector<int> rbuf(10); // std::vector의 내부 저장소 역시 배열입니다 std::size_t sz = std::fread(rbuf.data(), sizeof rbuf[0], rbuf.size(), f2); std::fclose(f2); for (std::size_t n = 0; n < sz; ++n) std::printf("%d\n", rbuf[n]); } } 출력: 42 -1 7 참고 항목
| ||||||||||||||||||||