Search code examples
c++bytenumeric-limits

Value of numeric_limits<streamsize>::max() in c++


While using cin.ignore() in c++, it takes an argument of number of characters to consume until the delimiter occurs. Most often I have observed the following to be used cin.ignore(numeric_limits<streamsize>::max(), '\n');

I was curious to know the value of numeric_limtis<streamsize>::max() so I just outputted its value and it came to be a humongous value of 9223372036854775807 . If it represents the number of characters, then it can be considered in bytes and if that's true, isn't this a very large value exceeding my HDD space.

Can someone please tell me what it actually is and why such a large value ?


Solution

  • isn't this a very large value exceeding my HDD space.

    That's exactly the purpose of this value. You want to skip as many char as possible. In fact, this value does indicate infinite, since the count test is disabled for this value:

    count characters were extracted. This test is disabled in the special case when count equals std::numeric_limits< std::streamsize >::max()