std::ios_base::seekdir
來自 cppreference.com
typedef /*實現定義*/ seekdir; |
||
static constexpr seekdir beg = /*實現定義*/ static constexpr 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); // <- 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> 的公共成員函式) |