Namespaces
Variants

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

From cppreference.net
pos_type tellg ( ) ;

現在関連付けられている streambuf オブジェクトの入力位置インジケータを返します。

UnformattedInputFunction として振る舞うが、 gcount() には影響を与えない。セントリオブジェクトの構築とチェックの後、 fail ( ) == true の場合、 pos_type ( - 1 ) を返す。それ以外の場合、 rdbuf ( ) - > pubseekoff ( 0 , std:: ios_base :: cur , std:: ios_base :: in ) を返す。

目次

パラメータ

(なし)

戻り値

成功時はゲットポインタの現在位置、 pos_type ( - 1 ) 失敗時。

例外

failure (注:このケースでは翻訳対象のテキスト「failure」はC++のクラス名であり、C++固有の用語に該当するため、翻訳せずにそのまま保持します) if an error occurred (the error state flag is not goodbit ) and exceptions() is set to throw for that state.

内部操作が例外をスローした場合、それはキャッチされ、 badbit が設定されます。 exceptions() badbit に対して設定されている場合、例外は再スローされます。

#include <iostream>
#include <sstream>
#include <string>
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

関連項目

[virtual]
ファイル位置を相対アドレッシングを使用して再配置する
( std::basic_filebuf<CharT,Traits> の仮想保護メンバ関数)
[virtual]
入力シーケンス、出力シーケンス、またはその両方の次のポインタを相対アドレッシングを使用して再配置する
( std::basic_stringbuf<CharT,Traits,Allocator> の仮想保護メンバ関数)
[virtual]
入力シーケンス、出力シーケンス、またはその両方の次のポインタを相対アドレッシングを使用して再配置する
( std::strstreambuf の仮想保護メンバ関数)
入力位置指示子を設定する
(公開メンバ関数)
出力位置指示子を返す
( std::basic_ostream<CharT,Traits> の公開メンバ関数)
出力位置指示子を設定する
( std::basic_ostream<CharT,Traits> の公開メンバ関数)