# std::ios_base::seekdir

> C++ Atlas: `cppatlas.com/w/cpp/io/ios_base/seekdir` | Source: https://en.cppreference.com/w/cpp/io/ios_base/seekdir | Domain: Input/output

Specifies file seeking direction type. The following constants are defined:

## Official Specification Summary (cppreference)

```cpp
typedef /*implementation defined*/ seekdir;

static constexpr seekdir beg = /*implementation defined*/
static constexpr seekdir end = /*implementation defined*/
static constexpr seekdir cur = /*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

### Example

```cpp
#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:

```text
word1 = Hello,
word2 = Hello,
word3 = World!
word4 = World!
word5 = World!
```

### See also

- [`seekg`](https://en.cppreference.com/w/cpp/io/basic_istream/seekg): sets the input position indicator (public member function of `std::basic_istream<CharT,Traits>`)
- [`seekp`](https://en.cppreference.com/w/cpp/io/basic_ostream/seekp): sets the output position indicator (public member function of `std::basic_ostream<CharT,Traits>`)
- [`pubseekoff`](https://en.cppreference.com/w/cpp/io/basic_streambuf/pubseekoff): invokes `seekoff()` (public member function of `std::basic_streambuf<CharT,Traits>`)

---
Attribution: content from https://en.cppreference.com/w/cpp/io/ios_base/seekdir (cppreference.com), licensed under CC-BY-SA 3.0 and GFDL. Modified: converted to markdown, study notes added. Offline snapshot of 9 February 2025.