Skip to content

Commit f2c2262

Browse files
committed
new page fpos_t.md
1 parent 95459a7 commit f2c2262

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

reference/cstdio.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
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
## マクロ

reference/cstdio/fpos_t.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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): ??

0 commit comments

Comments
 (0)