std::fstream use 32-bit int as pos_type even on x64 platform - by ZephrLee

Status : 

  Fixed<br /><br />
		This item has been fixed in the current or upcoming version of this product.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.

Sign in
to vote
ID 627639 Comments
Status Closed Workarounds
Type Bug Repros 2
Opened 12/3/2010 1:35:10 AM
Access Restriction Public


std::fstream (same for ifstrea, ofstream) defined in STL in VS2010 uses "int" as the type of "pos_type". As the "int" is only 32bit for both "win32" and "x64" platforms, it will fail if we use functions sucha as "tellg" "tellp" "seekg" "seekp" to handle files more than 2GBytes either on "win32" or "x64" platform. Of course, "filebuf::pubseekoff", "filebuf::pubseekpos" also fail.

I look up the stl implementation to find that:
typedef basic_fstream<char, char_traits<char> > fstream;
template<class _Elem,
	class _Traits>
	class basic_fstream
		: public basic_iostream<_Elem, _Traits>
	{	// input/output stream associated with a C stream
	typedef typename _Traits::pos_type pos_type;
template<> struct char_traits<char>
	{	// properties of a string or stream char element
	typedef streampos pos_type;
typedef fpos<_Mbstatet> streampos;
typedef int _Mbstatet;

It is difficult for me to understand why streampos is defined as int (streamoff is defined as __int64 instead, which is what I expect). As in VC, "int" is always 32-bit and you should use __int64 when you want use 64-bit no matter on "win32" or "x64". 

This problem brings me a lot of troubles. There even are not a walk around in fstream, all I can do is turn to FILE* instead (use _fseek64i and _ftell64i). But I would like to use the interface of fstream, so I hope some guys can fix this problem.
Sign in to post a comment.
Posted by Mike Laughton on 2/16/2012 at 1:56 PM
Thanks for your response, Stephan. If this fix is limited to a macro like you mentioned, is there any chance we can get it in the form of a patch or service pack update to VC10?

My team is experiencing this issue, and after finding this page I downloaded VC11 Developer Preview and confirmed that the problem is fixed. Unfortunately since the official VC11 release date is unknown we are in the uncomfortable position of not having a good path forward.

I'm willing to entertain any kind of workaround (even manual patching), as our existing options are not great.

Posted by Microsoft on 3/3/2011 at 9:24 PM

Thanks for reporting this bug. We've fixed it, and the fix will be available in VC11. streampos contains a 32-bit "conversion state", but also contains two 64-bit positions. The problem was that a 32-bit cast was hiding in a macro. We've fixed the cast, so large file support should work correctly now (regardless of x86/x64 platform).

If you have any further questions, feel free to E-mail me at .

Stephan T. Lavavej
Visual C++ Libraries Developer
Posted by Microsoft on 12/3/2010 at 2:20 AM
Thank you for your feedback, we are currently reviewing the issue you have submitted. If this issue is urgent, please contact support directly(