在线文档教程
C++
输入/输出 | Input/output

std::basic_istream::tellg

性病:基本[医]iStream::tellg

pos_type tellg(

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

表现为UnformattedInputFunction,除了gcount()不受影响。在构造和检查哨兵对象之后,如果fail() == true、回报pos_type(-1).否则,返回rdbuf()->pubseekoff(0,std::ios_base::cur,std::ios_base::in)...

参数

%280%29

返回值

GET指针的当前成功位置,pos_type(-1)在失败的时候。

例外

failure如果发生错误%28,则错误状态标志不是goodbit29%和exceptions()将被抛向那个州。

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

二次

#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

二次

另见

seekoff virtualrepositions the file position, using relative addressing (virtual protected member function of std::basic_filebuf)
seekoff virtualrepositions the next pointer in the input sequence, output sequence, or both, using relative addressing (virtual protected member function of std::basic_stringbuf)
seekoff virtualrepositions the next pointer in the input sequence, output sequence, or both, using relative addressing (virtual protected member function of std::strstreambuf)
seekgsets the input position indicator (public member function)
tellpreturns the output position indicator (public member function of std::basic_ostream)
seekpsets the output position indicator (public member function of std::basic_ostream)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/io/basic[医]iStream/tellg