std::basic_ostream<CharT,Traits>::tellp
來自 cppreference.com
< cpp | io | basic ostream
pos_type tellp(); |
||
返回當前關聯的 streambuf
物件的輸出位置指示符。
其行為與 UnformattedOutputFunction 相同(除了不實際執行輸出)。在構造並檢查哨兵物件之後: |
(C++11 起) |
如果 fail()==true,則返回 pos_type(-1)。否則,返回 rdbuf()->pubseekoff(0, std::ios_base::cur, std::ios_base::out)。
目錄 |
[編輯] 引數
(無)
[編輯] 返回值
成功時返回當前輸出位置指示符,如果發生故障則返回 pos_type(-1)。
[編輯] 示例
執行此程式碼
#include <iostream> #include <sstream> int main() { std::ostringstream s; std::cout << s.tellp() << '\n'; s << 'h'; std::cout << s.tellp() << '\n'; s << "ello, world "; std::cout << s.tellp() << '\n'; s << 3.14 << '\n'; std::cout << s.tellp() << '\n' << s.str(); }
輸出
0 1 13 18 hello, world 3.14
[編輯] 參閱
設定輸出位置指示器 (公有成員函式) | |
返回輸入位置指示符 ( std::basic_istream<CharT,Traits> 的公有成員函式) | |
設定輸入位置指示符 ( std::basic_istream<CharT,Traits> 的公有成員函式) |