此示例代码是否会在所有系统上产生两个相等的值?
#include <limits>
#include <iostream>
#include <string>
int main() {
std::cout << std::numeric_limits<std::streamsize>::max()<< '\n';
std::string example;
std::cout << example.max_size() << '\n';
}
此示例代码是否会在所有系统上产生两个相等的值?
#include <limits>
#include <iostream>
#include <string>
int main() {
std::cout << std::numeric_limits<std::streamsize>::max()<< '\n';
std::string example;
std::cout << example.max_size() << '\n';
}
正如C++11 Draft 27.5.2中所指定的,它是一种实现定义的类型,因此它的限制在不同的平台、编译器等之间并不总是相等的。
typedef 实现定义的流大小;
streamsize 类型是有符号基本整数类型之一的同义词。它用于表示在 I/O 操作中传输的字符数,或 I/O 缓冲区的大小。300
在理论上和实践中都绝对不能保证。例如在我的机器上打印:
9223372036854775807
4611686018427387903
作为记录,它是 Windows 上的 MSYS2 的 64 位 GCC 10.2.0。