-
Notifications
You must be signed in to change notification settings - Fork 172
new page: fwrite.md #1490
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
new page: fwrite.md #1490
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2f35dc0
new page: fwrite.md
rotarymars 4ac8177
Update reference/cstdio/fwrite.md
rotarymars 8be4213
added precise description in fwrite
rotarymars 7bd3dd5
Merge branch 'cpprefjp:master' into master
rotarymars 9125852
Merge branch 'master' of https://github.com/rotarymars/cpprefjp-site
rotarymars 28435a2
deleted extra information
rotarymars 222f890
unified expressions in fwrite
rotarymars f596c4c
added appropriate explanations for function with `restrict`
rotarymars 4710078
Added \n for fwrite.md
rotarymars b0cdd5c
Merge branch 'cpprefjp:master' into master
rotarymars File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| # fwrite | ||
| * cstdio[meta header] | ||
| * std[meta namespace] | ||
| * function[meta id-type] | ||
|
|
||
| ```cpp | ||
| namespace std { | ||
| size_t fwrite(const void *buffer, size_t size, size_t count, FILE *stream); | ||
| } | ||
| ``` | ||
|
|
||
| ## 概要 | ||
| ストリームに`count`個の`size`バイトの要素を書き込む。 | ||
|
|
||
| ストリーム内の位置は、書き込まれたバイトだけ進む。 | ||
|
|
||
| 書き込み時にエラーが発生した場合、ストリーム内の位置は不定である。 | ||
|
|
||
| また、書き込みには内部的に[`fputc`](/reference/cstdio/fputc.md)を使用する。 | ||
|
|
||
| ## 要件 | ||
| - `buffer`は有効なポインタであること。 | ||
| - `stream`は有効なファイルストリームであること。 | ||
| - `buffer`が指すメモリ領域と`stream`が指すファイルストリームの内部バッファが重複していないこと。 | ||
|
|
||
| ## 戻り値 | ||
| 正常に書き込むことのできた要素の数を返す。 | ||
|
|
||
| ## 効果 | ||
| `buffer`が指すメモリから`count`個の`size`バイトの要素を`stream`に書き込む。 | ||
|
|
||
| 書き込みエラーが生じなければ、書き込むデータの大きさは`count * size`バイトである。 | ||
|
|
||
| ## 例 | ||
| ```cpp example | ||
| #include <cstdio> | ||
|
|
||
| int main() { | ||
| std::FILE *file = std::fopen("output.txt", "w"); | ||
| if (!file) { | ||
| std::perror("ファイルを開けませんでした"); | ||
| return 1; | ||
| } | ||
|
|
||
| const char data[] = "Hello, World!\n"; | ||
| /* | ||
| 厳密には、sizeof(char)は1バイトであることが保証されているため、 | ||
| sizeof(data) - 1は、文字列の長さ(ヌル終端文字を除く)と等しくなる。 | ||
| */ | ||
| std::size_t count = std::fwrite(data, sizeof(char), sizeof(data) - 1, file); | ||
| std::printf("書き込んだデータの長さ: %zu\n", count); | ||
|
|
||
| std::fclose(file); | ||
| return 0; | ||
| } | ||
| ``` | ||
| * std::fwrite[color ff0000] | ||
| * std::fopen[link /reference/cstdio/fopen.md] | ||
| * std::fclose[link /reference/cstdio/fclose.md] | ||
| * std::perror[link /reference/cstdio/perror.md.nolink] | ||
| * std::printf[link /reference/cstdio/printf.md] | ||
|
|
||
| ### 出力例 | ||
| ``` | ||
| 書き込んだデータの長さ: 13 | ||
| ``` | ||
|
|
||
| ### ファイル出力(output.txt) | ||
| ``` | ||
| Hello, World! | ||
|
akinomyoga marked this conversation as resolved.
|
||
| ``` | ||
|
|
||
| ## 処理系 | ||
| - [Clang](/implementation.md#clang): ?? | ||
| - [GCC](/implementation.md#gcc): ?? | ||
| - [Visual C++](/implementation.md#visual_cpp): ?? | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.