std::ios_base::seekdir
来自 cppreference.com
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); // <- rewind in >> word2; in.seekg(1, std::ios_base::cur); // -> seek from cur pos toward the end in >> word3; in.seekg(-6, std::ios_base::cur); // <- seek from cur pos (end) toward begin in >> word4; in.seekg(-6, std::ios_base::end); // <- seek from end toward begin 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> 的公共成员函数) |