是std :: streampos保证无符号long long? [英] Is std::streampos guaranteed to be unsigned long long?

查看:776
本文介绍了是std :: streampos保证无符号long long?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

std :: streampos 保证是 unsigned long long



如果不是这样, std :: istream :: seekg 如何在大于4G的文件上正常工作?

解决方案

http:// en .cppreference.com / w / cpp / io / fpos

std :: streampos 是类模板的专门化

  template< / p> class State> class fpos; 

std :: streampos is typedef'ed每个类型的对象都是 std :: fpos >< st>>< / code> (code> std :: streamoff )的私有成员。

http:// en .cppreference.com / w / cpp / io / streamoff

std :: streamoff 是一个足够大小的带符号整数类型,用于表示操作系统支持的最大可能文件大小。通常,这是一个typedef long long



回答您的问题...



问题是 std :: streampos 保证是 unsigned long long

回答我相信你的意思是要找出是否保持位置的基本整数类型是保证 unsigned long long 。从这个意义上说,真正的问题是,是否将 std :: streamoff 保存为无符号long long 。这个问题的答案是否,正如你从上面的描述中推断出的那样。

问题如果不是这样, std :: istream :: seekg 在大于4G的文件上正常工作?

回答一个操作系统支持使用大于4G的文件,相应的是 std :: streamoff 。即使如此,这很可能是一个有符号整数类型。以下是 http://en.cppreference.com/w/cpp/io/streamoff
$ b


std :: streamoff值-1也用于表示一些I / O库函数。


Is std::streampos guaranteed to be unsigned long long?

If not so, how does std::istream::seekg work correctly on files larger than 4G?

解决方案

From http://en.cppreference.com/w/cpp/io/fpos:

std::streampos is a specialization of the class template

template< class State > class fpos;

std::streampos is typedef'ed to be std::fpos<std::char_traits<char>::state_type>

Each object of type fpos holds the byte position in the stream (typically as a private member of type std::streamoff).

From http://en.cppreference.com/w/cpp/io/streamoff:

The type std::streamoff is a signed integral type of sufficient size to represent the maximum possible file size supported by the operating system. Typically, this is a typedef to long long.

To answer your questions...

Question Is std::streampos guaranteed to be unsigned long long?

Answer I am sure you meant to find out whether the underlying integral type that holds the position is guaranteed to be unsigned long long. In that sense, the real question is whether std::streamoff is gueranteed to be unsigned long long. The answer to that question is "No", as you can infer from the descriptions above.

Question If not so, how does std::istream::seekg work correctly on files larger than 4G?

Answer If an operating system supports working with files larger than 4G, it's std::streamoff is typdef'ed accordingly. Even then, it is most likely going to be a signed integral type. Here's another quote from http://en.cppreference.com/w/cpp/io/streamoff.

A std::streamoff value of -1 is also used to represent error conditions by some of the I/O library functions.

这篇关于是std :: streampos保证无符号long long?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆