Namespaces
Variants

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

From cppreference.net
pos_type tellg ( ) ;

返回当前关联 streambuf 对象的输入位置指示器。

表现为 无格式输入函数 ,但 gcount() 不受影响。在构造并检查岗哨对象后,若 fail ( ) == true ,则返回 pos_type ( - 1 ) 。否则返回 rdbuf ( ) - > pubseekoff ( 0 , std:: ios_base :: cur , std:: ios_base :: in )

目录

参数

(无)

返回值

成功时获取指针的当前位置,失败时返回 pos_type ( - 1 )

异常

failure if an error occurred (the error state flag is not goodbit ) and exceptions() is set to throw for that state.

如果内部操作抛出异常,该异常会被捕获并设置 badbit 。如果为 badbit 设置了 exceptions() ,则异常会被重新抛出。

示例

#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> 的公开成员函数)