File tree Expand file tree Collapse file tree 2 files changed +68
-1
lines changed
Expand file tree Collapse file tree 2 files changed +68
-1
lines changed Original file line number Diff line number Diff line change 1010| ------| ------| ----------------|
1111| [ ` size_t ` ] ( /reference/cstddef/size_t.md ) | 符号なし整数型 | |
1212| [ ` FILE ` ] ( /reference/cstdio/file.md ) | ストリームの制御に必要な情報を持つオブジェクト型 | |
13- | [ ` fpos_t ` ] ( /reference/cstdio/fpos_t.md.nolink ) | ファイルの全ての位置にアクセスするための配列以外の完全オブジェクト型 | |
13+ | [ ` fpos_t ` ] ( /reference/cstdio/fpos_t.md ) | ファイルの全ての位置にアクセスするための配列以外の完全オブジェクト型 | |
1414
1515
1616## マクロ
Original file line number Diff line number Diff line change 1+ # fpos_t
2+ * cstdio[ meta header]
3+ * type-alias[ meta id-type]
4+ * std[ meta namespace]
5+
6+ ``` cpp
7+ namespace std {
8+ typedef /* implementation-defined * / fpos_t;
9+ }
10+ ```
11+
12+ ## 概要
13+ ファイルの位置を保持するための型。
14+
15+ [`fseek()`](/reference/cstdio/fseek.md.nolink)関数や[`ftell()`](/reference/cstdio/ftell.md.nolink)関数とは違い、巨大なファイルやマルチバイトファイルに対しても適切に動作するすることを目的に設計された。
16+
17+ ## 例
18+ ```cpp example
19+ #include <cstdio>
20+
21+ int main() {
22+ std::FILE *file = std::fopen("sample.txt", "r");
23+ if (!file) {
24+ std::perror("ファイルを開けませんでした");
25+ return 1;
26+ }
27+
28+ std::fpos_t pos;
29+ std::fgetpos(file, &pos); // ファイルの位置をposに保存する
30+
31+ int c = std::fgetc(file);
32+ std::printf("1文字目: %c\n", c);
33+
34+ std::fsetpos(file, &pos); // ファイルの読み取り位置をposにする
35+
36+ c = std::fgetc(file);
37+ std::printf("もう一度1文字目: %c\n", c);
38+
39+ std::fclose(file);
40+ return 0;
41+ }
42+
43+ ```
44+ * std::fpos_t[ color ff0000]
45+ * std::fgetpos()[ link /reference/cstdio/fgetpos.md.nolink]
46+ * std::fsetpos()[ link /reference/cstdio/fsetpos.md.nolink]
47+ * std::fopen()[ link /reference/cstdio/fopen.md]
48+ * std::fclose()[ link /reference/cstdio/fclose.md]
49+ * std::fgetc()[ link /reference/cstdio/fgetc.md]
50+ * std::printf()[ link /reference/cstdio/printf.md]
51+ * std::perror()[ link /reference/cstdio/perror.md.nolink]
52+
53+ ### ファイル内容(sample.txt)
54+ ```
55+ Hello, World!
56+ ```
57+
58+ ### 出力
59+ ```
60+ 1文字目: H
61+ もう一度1文字目: H
62+ ```
63+
64+ ## 処理系
65+ - [ Clang] ( /implementation.md#clang ) : ??
66+ - [ GCC] ( /implementation.md#gcc ) : ??
67+ - [ Visual C++] ( /implementation.md#visual_cpp ) : ??
You can’t perform that action at this time.
0 commit comments