Search code examples
c++extraction-operator

C++ extraction operator : how can one know the number of digits read?


I read an integer number :

is >> myInteger;

Now I want to know how many digits were read (I'm talking of the possible leading zeros). How can I do that?


Solution

  • You can:

    • get the value as a string, then parse it separately, however you wish (check length, count zeros, etc).

    • use is.tellg for this; Keep in mind that tellg will give you buffer positions, not not what was at those positions (it could be space characters or zeros)

    • read the buffer character by character using is.get, then process values according to your needs.