我有一个大的二进制文件正在读取,我想将当前位置与一个无符号的long long int进行比较。但是,根据C++文档,我不清楚是否:
任何答案或建议,将不胜感激。
最佳答案
问tellg()的返回类型是什么?
A istream::tellg()
的返回类型为streampos
。 checkout std::istream::tellg。
问如何将tellg()与无符号long long int进行比较?
tellg()
的返回值是整数类型。因此,您可以使用通常的运算符来比较两个int
。但是,您不应该这样做以得出任何结论。标准声称支持的唯一操作是:
checkout std::streampos。
Q tellg()的返回类型是否有一个最大值(来自numeric_limits)小于一个无符号long long int?
该标准没有任何声明支持或反驳它。在一个平台上可能为true,而在另一个平台上可能为false。
附加信息
比较streampos
,受支持和不受支持的比较操作示例
ifstream if(myinputfile);
// Do stuff.
streampos pos1 = if.tellg();
// Do more stuff
streampos pos2 = if.tellg();
if ( pos1 == pos2 ) // Supported
{
// Do some more stuff.
}
if ( pos1 != pos2 ) // Supported
{
// Do some more stuff.
}
if ( pos1 != pos2 ) // Supported
{
// Do some more stuff.
}
if ( pos1 == 0 ) // supported
{
// Do some more stuff.
}
if ( pos1 != 0) // supported
{
// Do some more stuff.
}
if ( pos1 <= pos2 ) // NOT supported
{
// Do some more stuff.
}
int k = 1200;
if ( k == pos1 ) // NOT supported
{
}
关于C++ tellg()返回类型,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/22996683/