Apache C++ Standard Library Reference Guide

## fpos

Library: Input/output

    Does not inherit

- Local Index
- Summary
- Synopsis
- Description
- Interface
- Member Types
- Constructors
- Public Member Functions
- Valid Operations
- See Also
- Standards Conformance

### Local Index

#### Members

fpos() operator!=() operator+() | operator+=() operator-() operator-=() | operator==() state() state_type | streamoff()

### Summary

Class that maintains position information for the iostream classes

### Synopsis

    #include <rw/iotraits>

    namespace std {
      template<class stateT>
      class fpos;
    }

### Description

The class template fpos is used by the iostream classes to maintain position information. It maintains the absolute position within the external sequence, and the conversion state at that position. Streams instantiated on narrow characters use streampos as their positioning type, whereas streams instantiated on wide characters use wstreampos.

### Interface

    namespace std {
      template <class stateT>
      class fpos {

       public:

        typedef stateT  state_type;

        fpos(streamoff off = 0,
             state_type = state_type());

        void        state(state_type);
        state_type  state() const;

        fpos& operator+=(streamoff);
        fpos& operator-=(streamoff);

        fpos& operator+(streamoff) const;
        fpos& operator-(streamoff) const;

        bool operator==(const fpos&) const;
        bool operator+=(const fpos&) const;

      };
    }

### Member Types

    state_type

The type `state_type` is an alias for the template parameter `stateT`.

### Constructors

    fpos(streamoff off = 0, state_type st = state_type());

Constructs an fpos object, initializing its position with `off` and its conversion state with `st`.

### Public Member Functions

    state_type
    state() const;

Returns the conversion state stored in the fpos object.

    void
    state(state_type st);

Stores `st` as the new conversion state in the fpos object.

    operator streamoff() const;

Returns the offset part of the fpos object without the state information.

    fpos& operator+=(streamoff off);
    fpos& operator-=(streamoff off);

Adds or subtracts `off` to or from an fpos object and assigns the result to it.

    fpos& operator+(streamoff off) const;
    fpos& operator-(streamoff off) const;

Adds or subtracts `off` to or from an fpos object.

    bool operator==(const fpos&) const;
    bool operator!=(const fpos&) const;

Compares two fpos objects for [in]equality.

### Valid Operations

In the following,

- `P` refers to type `fpos<stateT>`

- `p` and `q` refer to a value of type `fpos<stateT>`

- `O` refers to the offset type (`streamoff`, `wstreamoff`, `long` ...)

- `o` refers to a value of the offset type

- `i` refers to a value of type `int`

Valid operations:

`P p( i );` | Constructs from `int`
`P p = i;` | Assigns from `int`
`P( o )` | Converts from offset
`O( p )` | Converts to offset
`p == q` | Tests for equality
`p != q` | Tests for inequality
`q = p + o` | Adds offset
`p += o` | Adds offset
`q = p -o` | Subtracts offset
`q -= o` | Subtracts offset
`o = p - q` | Returns offset

### See Also

<iosfwd>, char_traits

### Standards Conformance

ISO/IEC 14882:1998 -- International Standard for Information Systems --Programming Language C++, Section 27.4.3. See also ISO/IEC 9899/AMD1:1995, Amendment 1 to ISO/IEC 9899:1990 C Integrity.