std::basic_istream<CharT,Traits>::tellg
来自cppreference.com
                    
                                        
                    < cpp | io | basic istream
                    
                                                            
                    |   pos_type tellg();  | 
||
返回当前关联的 streambuf 对象的输入位置指示器。
表现为无格式输入函数 (UnformattedInputFunction) ,除了不影响 gcount() 。构造并检查 sentry 对象后,若 fail() == true ,则返回 pos_type(-1) 。否则,返回 rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::in) 。
参数
(无)
返回值
成功时为获取指针的当前位置,失败时为 pos_type(-1) 。
异常
如果内部操作抛出异常,那么捕获它并设置 badbit。如果对 badbit 设置了 exceptions(),那么就会重抛该异常。
示例
运行此代码
#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> 的虚受保护成员函数)  | 
|    [虚]  | 
  用相对寻址,重定位输入序列、输出序列或两者中的下一位置指针  ( std::basic_stringbuf<CharT,Traits,Allocator> 的虚受保护成员函数)  | 
|    [虚]  | 
  用相对寻址重寻位输入序列、输出序列或两者中的下一位置指针  ( std::strstreambuf 的虚受保护成员函数)  | 
|    设置输入位置指示器   (公开成员函数)  | |
|   返回输出位置指示器  ( std::basic_ostream<CharT,Traits> 的公开成员函数)  | |
|   设置输出位置指示器  ( std::basic_ostream<CharT,Traits> 的公开成员函数)  |