std::ios_base::seekdir
来自cppreference.com
typedef/* 由实现定义 */ seekdir; | ||
staticconstexpr seekdir beg =/* 由实现定义 */ staticconstexpr seekdir end =/* 由实现定义 */ | ||
指定文件寻位方向类型。定义了下列常量:
常量 | 解释 |
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> 的公开成员函数) |