##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::fseek

From cppreference.com
< cpp‎ | io‎ | c

Defined in header `<cstdio>` |  |
int fseek( std::FILE* stream, long offset, int origin ); |  |

Sets the file position indicator for the file stream `stream`.

If the `stream` is open in binary mode, the new position is exactly `offset` bytes measured from the beginning of the file if `origin` is SEEK_SET, from the current file position if `origin` is SEEK_CUR, and from the end of the file if `origin` is SEEK_END. Some binary streams may not support the SEEK_END.

If the `stream` is open in text mode, the only supported values for `offset` are zero (which works with any `origin`) and a value returned by an earlier call to std::ftell on a stream associated with the same file (which only works with `origin` of SEEK_SET.

In addition to changing the file position indicator, `fseek` undoes the effects of std::ungetc and clears the end-of-file status, if applicable.

If a read or write error occurs, the error indicator for the stream (std::ferror) is set and the file position is unaffected.

### [edit] Parameters

stream | - | file stream to modify
offset | - | number of characters to shift the position relative to origin
origin | - | position to which `offset` is added. It can have one of the following values: SEEK_SET, SEEK_CUR, SEEK_END

### [edit] Return value

​0​ upon success, nonzero value otherwise.

### [edit] Example

| This section is incomplete Reason: no example

### [edit] See also

fsetpos | moves the file position indicator to a specific location in a file (function) [edit]
fgetpos | gets the file position indicator (function) [edit]
ftell | returns the current file position indicator (function) [edit]
rewind | moves the file position indicator to the beginning in a file (function) [edit]
C documentation for fseek

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/io/c/fseek&oldid=62309"
Category:

- Todo no example