std::basic_ostream<CharT,Traits>::tellp
来自cppreference.com
| |
||
返回当前关联的 streambuf 对象的输出位置指示器。
|
表现为无格式输出函数 (UnformattedOutputFunction) (除了不实际进行输出)。在构造并检查 sentry 对象后, |
(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> 的公开成员函数) |