std::basic_istream<CharT,Traits>::tellg
来自 cppreference.cn
< cpp | io | basic istream
pos_type tellg(); |
||
返回当前关联的 streambuf
对象的输入位置指示符。
行为类似于 UnformattedInputFunction,除了 gcount() 不受影响。构造并检查守卫对象后,如果 fail() == true,则返回 pos_type(-1)。否则,返回 rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::in)。
目录 |
[编辑] 参数
(无)
[编辑] 返回值
成功时,返回 get 指针的当前位置;失败时,返回 pos_type(-1)。
[编辑] 异常
如果内部操作抛出异常,则捕获该异常并设置 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> 的公有成员函数) |