Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

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

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

      Returns input position indicator of the current associatedstreambuf object.

      Behaves asUnformattedInputFunction, except thatgcount() is not affected. After constructing and checking the sentry object, iffail()==true, returnspos_type(-1). Otherwise, returnsrdbuf()->pubseekoff(0,std::ios_base::cur,std::ios_base::in).

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      The current position of the get pointer on success,pos_type(-1) on failure.

      [edit]Exceptions

      [edit]
      failure if an error occurred (the error state flag is notgoodbit) andexceptions() is set to throw for that state.

      If an internal operation throws an exception, it is caught andbadbit is set. Ifexceptions() is set forbadbit, the exception is rethrown.

      [edit]Example

      Run this code
      #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';}

      Output:

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

      [edit]See also

      [virtual]
      repositions the file position, using relative addressing
      (virtual protected member function ofstd::basic_filebuf<CharT,Traits>)[edit]
      [virtual]
      repositions the next pointer in the input sequence, output sequence, or both, using relative addressing
      (virtual protected member function ofstd::basic_stringbuf<CharT,Traits,Allocator>)[edit]
      [virtual]
      repositions the next pointer in the input sequence, output sequence, or both, using relative addressing
      (virtual protected member function ofstd::strstreambuf)[edit]
      sets the input position indicator
      (public member function)[edit]
      returns the output position indicator
      (public member function ofstd::basic_ostream<CharT,Traits>)[edit]
      sets the output position indicator
      (public member function ofstd::basic_ostream<CharT,Traits>)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/io/basic_istream/tellg&oldid=158538"

      [8]ページ先頭

      ©2009-2025 Movatter.jp