Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ios::seekdir invalid conversion from 'std::ios_base::seek_dir {aka int}' to 'std::ios_base::seekdir {aka std::_Ios_Seekdir}'

28 views
Skip to first unread message

jara...@skynet.be

unread,
Jul 28, 2016, 10:00:49 AM7/28/16
to
Hi,

the following code should compile according to the standard (library).

#include <iostream>
using std::ios;
#include <fstream>



int main() {
int offset = 0;
ios::seek_dir org;
org= ios::beg;
std::ifstream input("Test.txt");
input.seekg(offset, org);
return 0;
}


g++ (5.4.0) gives the following error messages:

IOS_Test.C: In function 'int main()':
IOS_Test.C:12:26: error: invalid conversion from 'std::ios_base::seek_dir {aka int}' to
'std::ios_base::seekdir {aka std::_Ios_Seekdir}' [-fpermissive]
input.seekg(offset, org);
^
In file included from /usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/iostream:40:0,
from IOS_Test.C:1:
/usr/lib/gcc/x86_64-pc-linux-gnu/5.4.0/include/g++-v5/istream:602:7: note:
initializing argument 2 of 'std::basic_istream<_CharT, _Traits>& std::basic_istream<_CharT, _Traits>::seekg
(std::basic_istream<_CharT, _Traits>::off_type, std::ios_base::seekdir)
[with _CharT = char; _Traits = std::char_traits<char>; std::basic_istream<_CharT,
_Traits>::off_type = long int; std::ios_base::seekdir = std::_Ios_Seekdir]'
seekg(off_type, ios_base::seekdir);

Is this a bug or what am I missing?

Many thanks for a hint,
Helmut

Öö Tiib

unread,
Jul 28, 2016, 1:21:35 PM7/28/16
to
On Thursday, 28 July 2016 17:00:49 UTC+3, jara...@skynet.be wrote:
> Hi,
>
> the following code should compile according to the standard (library).

What standard library? Cite, link, quote?
Yes it is your bug and compiler complains cleanly. All you need is to
read a bit of docks. I can highlight the points: That 'ios_base::beg'
is of type 'ios_base::seekdir'. That 'ios_base::seek_dir' that you use
is deprecated member type and compatibility with 'ios_base::seekdir'
is nowhere required. See yourself:
http://en.cppreference.com/w/cpp/io/ios_base

jara...@skynet.be

unread,
Jul 28, 2016, 1:35:48 PM7/28/16
to
Many thanks!
I didn't realize that there are two different type(def)s:
seekdir and seek_dir.

Helmut.
0 new messages