名稱空間
變體
操作

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

來自 cppreference.com
< 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)

[編輯] 異常

如果發生錯誤(錯誤狀態標誌不是 goodbit)並且 exceptions() 被設定為對該狀態丟擲異常,則丟擲 failure

如果內部操作丟擲異常,則捕獲該異常並設定 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> 的公有成員函式) [編輯]