std::getline
提供: cppreference.com
< cpp | string | basic string
![]() |
このページは、Google 翻訳を使って英語版から機械翻訳されました。
翻訳には誤りや奇妙な言い回しがあるかもしれません。文章の上にポインタをおくと、元の文章が見れます。誤りを修正して翻訳を改善する手助けをしてください。翻訳についての説明は、ここをクリックしてください。 |
Defined in header <string>
|
||
template< class CharT, class Traits, class Allocator > std::basic_istream<CharT,Traits>& getline( std::basic_istream<CharT,Traits>& input, |
(1) | |
template< class CharT, class Traits, class Allocator > std::basic_istream<CharT,Traits>& getline( std::basic_istream<CharT,Traits>&& input, |
(1) | (C++11およびそれ以降) |
template< class CharT, class Traits, class Allocator > std::basic_istream<CharT,Traits>& getline( std::basic_istream<CharT,Traits>& input, |
(2) | |
template< class CharT, class Traits, class Allocator > std::basic_istream<CharT,Traits>& getline( std::basic_istream<CharT,Traits>&& input, |
(2) | (C++11およびそれ以降) |
getline
入力ストリームから文字を読み込み、文字列にそれらを配置しますOriginal:
getline
reads characters from an input stream and places them into a string:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
1)
UnformattedInputFunction
が影響されない点を除いて、input.gcount()
として動作します。構築し、監視オブジェクトをチェックした後、次の手順を実行しますOriginal:
Behaves as
UnformattedInputFunction
, except that input.gcount()
is not affected. After constructing and checking the sentry object, performs the following:The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
1)
str.erase()呼び出します
Original:
Calls str.erase()
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
次のいずれかが発生する(表示されている順序でチェックされる)まで
input
にstr
を付加そこから文字を抽出しますOriginal:
Extracts characters from
input
and appends them to str
until one of the following occurs (checked in the order listed)The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
a)
input
でend-of-file状態、ケース内、getline
セットeofbitとリターン.Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
b)
次の使用可能な入力文字は、区切り文字が
delim
から抽出された場合で、Traits::eq(c, delim)、によってテスト、input
ですが、str
に追加されません.Original:
the next available input character is
delim
, as tested by Traits::eq(c, delim), in which case the delimiter character is extracted from input
, but is not appended to str
.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
c)
str.max_size()文字は大文字で
getline
セットfailbitと戻り、保存されていた.Original:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
3)
文字が何らかの理由(NULLすらない捨て区切り文字)、
getline
セットfailbitとリターンのために抽出されなかった場合は.Original:
If no characters were extracted for whatever reason (not even the discarded delimiter),
getline
sets failbit and returns.The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
2)
getline(input, str, input.widen(’\n’))と同じ、つまり、デフォルトの区切り文字は行末文字です.
Original:
Same as getline(input, str, input.widen(’\n’)), that is, the default delimiter is the endline character.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
[編集] パラメータ
input | - | からデータを取得するためのストリーム
Original: the stream to get 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 | - | にデータを格納する文字列
Original: the string to put the data into The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
delim | - | 区切り文字
Original: the delimiter character The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[編集] 値を返します
input
[編集] 例
次のコードは、その名前を使用してそれらを迎えた後、自分の名前の入力をユーザーに要求します.
Original:
The following code asks the user for their name, then greets them using that name.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
このコードを実行します
#include <string> #include <iostream> int main() { std::string name; std::cout << "What is your name? "; std::getline(std::cin, name); std::cout << "Hello " << name << ", nice to meet you."; }
Possible output:
What is your name? John Q. Public Hello John Q. Public, nice to meet you.