名前空間
変種
操作

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

From cppreference.com
< cpp‎ | io‎ | basic istream
 
 
 
 
pos_type tellg();

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

gcount()に影響がない点を除き、UnformattedInputFunctionとして動作します。 sentryオブジェクトを構築してチェックした後、fail() == trueの場合は、pos_type(-1)を返します。それ以外の場合は、rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::in)を返します。

目次

[編集] パラメータ

(なし)

[編集] 戻り値

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

[編集] 例外

failure: エラーが発生した場合(エラー状態フラグが goodbit ではない)で、exceptions() がその状態に対してスローするように設定されている場合。

内部操作が例外をスローした場合、それはキャッチされ、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]
相対アドレスを使用してファイル位置を再配置します
(virtual protected member function of std::basic_filebuf<CharT,Traits>) [編集]
[virtual]
入力シーケンス、出力シーケンス、またはその両方で、相対アドレス指定を使用して次のポインタを再配置する
(virtual protected member function of std::basic_stringbuf<CharT,Traits,Allocator>) [編集]
[virtual]
入力シーケンス、出力シーケンス、またはその両方で、相対アドレス指定を使用して次のポインタを再配置する
(virtual protected member function of std::strstreambuf) [編集]
入力位置インジケータを設定する
(public member function) [編集]
出力位置インジケータを返す
(std::basic_ostream<CharT,Traits> の public メンバ関数) [編集]
出力位置インジケータを設定する
(std::basic_ostream<CharT,Traits> の public メンバ関数) [編集]
English 日本語 中文(简体) 中文(繁體)