Cpp-standard-library-cpp-basic-ios-get

提供:Dev Guides
移動先:案内検索

C ++ basic_iosライブラリ-取得

説明

文字を取得するために使用されます。

宣言

以下は、std
basic_istream :: getの宣言です。
er (1)
int_type get();
basic_istream& get (char_type& c);
c-string (2)
basic_istream& get (char_type* s, streamsize n);
basic_istream& get (char_type* s, streamsize n, char_type delim);
stream buffer (3)
basic_istream& get (basic_streambuf<char_type,traits_type>& sb);
basic_istream& get (basic_streambuf<char_type,traits_type>& sb, char_type delim);

パラメーター

  • c -抽出された値が保存されている文字への参照。
  • s -抽出された文字がC文字列として保存される文字の配列へのポインタ。
  • n -sに書き込む最大文字数(終端のヌル文字を含む)。
  • delim -明示的な区切り文字:連続する文字を抽出する操作は、抽出する次の文字がこれと等しいとすぐに停止します(traits_type :: eqを使用)。
  • sb -制御された出力シーケンスで文字がコピーされるbasic_streambufオブジェクト。

戻り値

読み込まれた文字を返します。ストリームで使用可能な文字がない場合はファイルの終わり値(traits_type
eof())を返します(この場合、failbitフラグも設定されていることに注意してください)。

例外

基本保証-例外がスローされた場合、オブジェクトは有効な状態です。

データの競合

c、sb、またはsが指す配列内の要素を変更し、ストリームオブジェクトを変更します。

以下のstd
basic_istream :: getの例では。
#include <iostream>
#include <fstream>

int main () {
   char str[256];

   std::cout << "Enter the name of an existing text file: ";
   std::cin.get (str,256);

   std::ifstream is(str);

   char c;
   while (is.get(c))
      std::cout << c;

   is.close();

   return 0;
}