1

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 ?

3
  • It's the absolute maximum number of characters that the stream buffer can theoretically support. It's effectively a way of saying "ignore characters without limit, until we see the delimiter". Commented Oct 30, 2018 at 13:58
  • 1
    Also, that humongous number is precisely 2^63 - 1, which is the maximal value of a signed 64bit integer. Commented Oct 30, 2018 at 14:00
  • note that streamsize is just a typedef. Afaik also with containers you would run into problems before you push numeric_limits<size_t>::max() elements. I think those are just telling you what the types can support, while you seem to care about what your physical hardware can support Commented Oct 30, 2018 at 14:00

2 Answers 2

6

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()

Sign up to request clarification or add additional context in comments.

Comments

1

numeric_limtis<streamsize>::max() gives you the maximum value an object of streamsize can hold. This isn't actually how many characters can be in the buffer, it's just what the type the buffer uses supports. If you had a big enough machine with enough memory then you could get 9,223,372,036,854,775,807 characters in the buffer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.