std::ios_base::seekdir
From cppreference.com
C++
Feature test macros (C++20)
Concepts library (C++20)
Metaprogramming library (C++11)
Ranges library (C++20)
Filesystem library (C++17)
Concurrency support library (C++11)
Execution control library (C++26)
Input/output library
Print functions (C++23)
Buffers
(C++23)
(C++98/26*)
(C++20)
Streams
Abstractions
File I/O
String I/O
Array I/O
(C++23)
(C++23)
(C++23)
(C++98/26*)
(C++98/26*)
(C++98/26*)
Synchronized Output
(C++20)
Types
Error category interface
(C++11)
(C++11)
std::ios_base
Member functions
Formatting
Locales
Internal extensible array
Miscellaneous
Member classes
Member types
ios_base::seekdir
typedef /*implementation defined*/ seekdir;
static constexpr seekdir beg = /*implementation defined*/
static constexpr seekdir end = /*implementation defined*/
Specifies file seeking direction type. The following constants are defined:
Constant
Explanation
beg
the beginning of a stream
end
the ending of a stream
cur
the current position of stream position indicator
[edit] Example
Run this code
#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'; }
Output:
word1 = Hello, word2 = Hello, word3 = World! word4 = World! word5 = World!
[edit] See also
sets the input position indicator
(public member function of
(public member function of
std::basic_istream<CharT,Traits>
) [edit]
sets the output position indicator
(public member function of
(public member function of
std::basic_ostream<CharT,Traits>
) [edit]