名前空間
変種
操作

std::fgets

提供: 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>
char *fgets( char *str, int count, FILE *stream );
与えられたファイルストリームから最もcount - 1文字で読み取り、strに格納します。生成された文字列は常にNULLで終了します。解析では、ファイルの終わりが発生した場合に停止するか、改行文字がstr、その改行文字が含まれていますが、その場合には、発見された.
Original:
Reads at most count - 1 characters from the given file stream and stores them in str. The produced character string is always NULL-terminated. Parsing stops if end-of-file occurs or a newline character is found, in which case str will contain that newline character.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

目次

[編集] パラメータ

str -
に文字を読み込むための文字列
Original:
string to read the characters to
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
count -
strの長さ
Original:
the length of str
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
stream -
からデータを読み込むためのストリームをファイルしてください
Original:
file stream to read the data from
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.

[編集] 値を返します

成功した場合にstr、エラー時にNULL
Original:
str on success, NULL on an error
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 <cstdlib>
 
int main()
{
    FILE* tmpf = std::tmpfile();
    std::fputs("Alan Turing\n", tmpf);
    std::fputs("John von Neumann\n", tmpf);
    std::fputs("Alonzo Church\n", tmpf);
 
    std::rewind(tmpf);
    char buf[8];
    while (std::fgets(buf, sizeof buf, tmpf) != NULL) {
        std::cout << '"' << buf << '"' << '\n';
    }
}

Output:

"Alan Tu"
"ring
"
"John vo"
"n Neuma"
"nn
"
"Alonzo "
"Church
"

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

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]
stdinから文字列を読み込みます
Original:
reads a character string from stdin
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 a character string to 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]
C documentation for fgets