Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-402

long long stream extraction fails for strings longer than 9 decimal characters

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 4.1.2, 4.1.3, 4.1.4
    • 4.2.0
    • 27. Input/Output
    • None
    • Incorrect Behavior

    Description

      The following test case:

      $ cat t.cpp
      #include <ios>
      #include <iostream>
      #include <sstream>

      int
      main ()
      {
      long long n = 0;

      { std::stringstream s (std::string ("214748364")); s >> n; std::cout << n << "\n"; } { std::stringstream s (std::string ("2147483640")); s >> n; std::cout << n << "\n"; }

      return 0;
      }

      Produces inconsistent (but consistently wrong) results in different runs:

      $ ./t
      214748364
      9223372036854775807
      $ ./t
      214748364
      214748365089
      $ ./t
      214748364
      9223372036854775807

      Liviu

      Attachments

        Activity

          People

            sebor Martin Sebor
            lnicoara Liviu Nicoara
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: