christo
christo

Reputation: 19

In C++ maximum std::streamsize is always equals to std::string max_size()?

Does this example code result two equal values on all systems?

#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';
}

Upvotes: 0

Views: 230

Answers (2)

Nikita Smirnov
Nikita Smirnov

Reputation: 862

As specified at C++11 Draft 27.5.2, it is an implementation defined type, so it's limits are not always equal across different platforms, compilers etc.

typedef implementation-defined streamsize;

The type streamsize is a synonym for one of the signed basic integral types. It is used to represent the number of characters transferred in an I/O operation, or the size of I/O buffers.300

Upvotes: 2

yeputons
yeputons

Reputation: 9238

Absolutely not guaranteed neither in theory, nor in practice. E.g. on my machine it prints:

9223372036854775807
4611686018427387903

For the record, it's a 64-bit GCC 10.2.0 by MSYS2 on Windows.

Upvotes: 1

Related Questions