命名空间
变体
操作

std::basic_ostream<CharT,Traits>::tellp

来自 cppreference.cn
< 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)

内容

[edit] 参数

(无)

[edit] 返回值

成功时返回当前输出位置指示器,如果发生错误则返回 pos_type(-1)。

[edit] 示例

#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

[edit] 参见

设置输出位置指示器
(public member function) [edit]
返回输入位置指示器
(public member function of std::basic_istream<CharT,Traits>) [edit]
设置输入位置指示器
(public member function of std::basic_istream<CharT,Traits>) [edit]