File Size Too Large (>4GB) Problem

using : MinGW 4.4.0, Windows Vista 32 bit

1
2
3
4
5
6
7
8
9
std::fstream ifs;
ifs.open("hugeFile",std::fstream::in | std::fstream::binary);
std::string line;

while(getline(ifs,line) {
   //both these will lead to error once the value of 2^32 is crossed
   unsigned int pos = ifs.tellg();
   ifs.seekg(pos);
}

what could be the simplest (relatively smaller learning curve) replacement to this? i've never used win32 API's though i'm familiar with boost as i use boost::regex very often. I just need the facility to seek and obtain the file pointer position which is a stumbling block to my application
This is because you're using the wrong unit for pos. Use instead:

streampos pos;

And you'll be fine.

For more details, check:

http://www.cplusplus.com/reference/iostream/istream/tellg/
closed account (o1vk4iN6)
http://www.cplusplus.com/forum/general/8515/
@TheDestroyer:
Thanks. i dont know why i thought streampos is typedef'd to unsigned int; but sizeof() returned 16 so i guess it's more than fine.

@xerzi:
Thanks
In the link you gave helios writes
On 32-bit implementations, the standard library has a random access seek limit of 2^31-1 bytes (just below 2 GiB).
This contradicts the sizeof(std::streampos) which is 16. What is happening here?
Outdated, maybe?

This is what MSDN says ('streampos is of type fpos is of type streamoff'):
http://msdn.microsoft.com/en-us/library/484tzsxy(v=vs.110).aspx
You're welcome.

This is why we call it an object oriented language. Everything has its right type. Don't extrapolate types yourself, so that you can keep your code valid for the future as long as possible. In the future when computers are 256 bits, your code wouldn't be valid anymore if you use your own types. Stick to the types provided by the standard for the function used by the standard.

Cheers :-)
Topic archived. No new replies allowed.