std::ios_base:: seekdir
From cppreference.net
|
typedef
/*implementation defined*/
seekdir
;
|
||
|
static
constexpr
seekdir beg
=
/*implementation defined*/
static
constexpr
seekdir end
=
/*implementation defined*/
|
||
指定文件寻址方向类型。定义了以下常量:
| 常量 | 说明 |
| beg | 流的起始位置 |
| end | 流的结束位置 |
| cur | 流位置指示器的当前位置 |
示例
运行此代码
#include <iostream> #include <sstream> #include <string> int main() { std::istringstream in("Hello, World!"); std::string word1, word2, word3, word4, word5; in >> word1; in.seekg(0, std::ios_base::beg); // <- 回退 in >> word2; in.seekg(1, std::ios_base::cur); // -> 从当前位置向末尾定位 in >> word3; in.seekg(-6, std::ios_base::cur); // <- 从当前位置(末尾)向开头定位 in >> word4; in.seekg(-6, std::ios_base::end); // <- 从末尾向开头定位 in >> word5; std::cout << "word1 = " << word1 << '\n' << "word2 = " << word2 << '\n' << "word3 = " << word3 << '\n' << "word4 = " << word4 << '\n' << "word5 = " << word5 << '\n'; }
输出:
word1 = Hello, word2 = Hello, word3 = World! word4 = World! word5 = World!
参见
|
设置输入位置指示器
(
std::basic_istream<CharT,Traits>
的公开成员函数)
|
|
|
设置输出位置指示器
(
std::basic_ostream<CharT,Traits>
的公开成员函数)
|
|
|
调用
seekoff
(
)
(
std::basic_streambuf<CharT,Traits>
的公开成员函数)
|