Why this fail to compile

Hi all:
i read the seekg reference http://www.cplusplus.com/reference/iostream/istream/seekg/ which states that the return value is *this,

so i think function all like this
1
2
ifstream infile(argv[1]);
infile.seekg(0,ios_base::end).close()

should compile smoothly,however,it is not the case

 error: 'struct std::basic_istream<char, std::char_traits<char> >' has no member named 'close'

on the other hand,i doubt its return value,please see code below

int i = infile.seekg(0,ios_base::end);


[Error]CProgrammingChallenge\filesize.cpp:18: error: invalid conversion from `void*' to `int'


PS:I use mingw5 for the code to compile,so is this a bug or it is not fully standard-compliant?

so,how to resolve these ?

Thanks in advance!
Last edited on
Why are you using close function this way

infile.seekg(0,ios_base::end).close()


use separate lines .

i
1
2
nfile.seekg(0,ios_base::end);
infile.close();
i know for sure it is ugly to write code like that,but,here i just want to test the return value of seekg.
Are you trying work out the file size? If so, that's a really bad way to do it.
@kbw ,yes,i already have a workable version using the seekg function, but i dont quite get you that it is a bad way to do that? Is there any deep or subtle problem?
Topic archived. No new replies allowed.