1

I'm reading the C++ standard but I can't figure this out. I am looking at code in some of our source files from many years ago:

streampos pos = inputfile.tellg();
if(pos < 0)
// an error
or
streampos pos = outputfile.tellp();
if(pos < 0)
// an error

I have 2 questions. The first is whether or not that code is ok and why, and the second does any C++ standard imply whether streampos is always signed or unsigned? I can't find where in the C++ 03 standard it says that. inputfile/outputfile are ifstream/ofstream. The closest thing I can find is not in the standard but cplusplus.com which says "Objects of this class support construction and conversion from int". Does that mean this comparison is fine?

newguy
  • 537
  • 4
  • 12
  • @r-sahu I don't see the answer to my question. I'm asking if it's always signed or unsigned, is that answered in the duplicate? I don't see it. streamoff seems to always be signed but I can't tell about streampos – newguy Sep 01 '17 at 18:07
  • @RSahu I don't see what you were referring to, but I believe it's the same story as with `std::string::npos`. At least the result is `pos_type`. – user0042 Sep 01 '17 at 18:18
  • @user0042 The real answer is that `streampos` holds a member variable of type `streamoff`, which is the required to be signed. – R Sahu Sep 01 '17 at 18:34

0 Answers0