名前空間
変種
操作

std::basic_istream<CharT,Traits>::tellg

提供: cppreference.com
< cpp‎ | io‎ | basic istream
 
 
入出力ライブラリ
入出力マニピュレータ
Cスタイルの入出力
バッファ
(C++98で非推奨)
ストリーム
抽象
ファイル入出力
文字列入出力
配列入出力
(C++98で非推奨)
(C++98で非推奨)
(C++98で非推奨)
同期化出力
エラーカテゴリインタフェース
(C++11)
 
 
pos_type tellg();

現在紐付けられている streambuf オブジェクトの入力位置指示子を返します。

UnformattedInputFunction として動作しますが、 gcount() は影響を受けません。 sentry オブジェクトの構築および確認の後、 fail() == true であれば pos_type(-1) を返します。 そうでなければ rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::in) を返します。

目次

[編集] 引数

(なし)

[編集] 戻り値

成功した場合は get ポインタの現在位置、失敗した場合は pos_type(-1)

[編集] 例外

エラーが発生し (エラー状態フラグが goodbit でなく)、その状態に対して投げるために exceptions() がセットされている場合は failure

内部の操作が例外を���げた場合、それはキャッチされ、 badbit がセットされます。 exceptions()badbit に対してセットされていれば、その例外が投げ直されます。

[編集]

#include <iostream>
#include <string>
#include <sstream>
 
int main()
{
    std::string str = "Hello, world";
    std::istringstream in(str);
    std::string word;
    in >> word;
    std::cout << "After reading the word \"" << word
              << "\" tellg() returns " << in.tellg() << '\n';
}

出力:

After reading the word "Hello," tellg() returns 6

[編集] 関連項目

[仮想]
相対位置を使用してファイル位置を再設定します
(std::basic_filebuf<CharT,Traits>の仮想プロテクテッドメンバ関数) [edit]
[仮想]
入力シーケンス、出力シーケンス、または両方の次ポインタの位置を、相対位置を用いて再設定します
(std::basic_stringbuf<CharT,Traits,Allocator>の仮想プロテクテッドメンバ関数) [edit]
[仮想]
相対位置を使用して入力シーケンス、出力シーケンス、またはその両方の次ポインタの位置を再設定します
(std::strstreambufの仮想プロテクテッドメンバ関数) [edit]
入力位置指示子を設定します
(パブリックメンバ関数) [edit]
出力位置指示子を返します
(std::basic_ostream<CharT,Traits>のパブリックメンバ関数) [edit]
出力位置指示子を設定します
(std::basic_ostream<CharT,Traits>のパブリックメンバ関数) [edit]