Oct 27, 2010 at 12:15pm UTC
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 Oct 27, 2010 at 12:22pm UTC
Oct 27, 2010 at 12:23pm UTC
i know for sure it is ugly to write code like that,but,here i just want to test the return value of seekg.
Oct 27, 2010 at 12:35pm UTC
Are you trying work out the file size? If so, that's a really bad way to do it.
Oct 27, 2010 at 4:28pm UTC
@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?