Streams and commas

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • John

    #1

    Streams and commas

    Hello,

    Why does the following code print "fail" instead of "123"
    in the vc 2005 beta?

    Thanks

    -John

    #include "stdafx.h"

    #include <sstream>

    int _tmain(int argc, _TCHAR* argv[])
    {
    std::stringstre am ss("123,456");

    int x;

    ss >> x;

    if (ss.fail()) {
    printf("fail");
    } else {
    printf("%d", x);
    }

    return 0;
    }
  • ismailp

    #2
    Re: Streams and commas

    what beta do you use?

    Comment

    • John Ky

      #3
      Re: Streams and commas

      Beta 2

      ismailp wrote:[color=blue]
      > what beta do you use?
      >[/color]

      Comment

      • Jason Murphy

        #4
        RE: Streams and commas

        why do you use "<sstream>" ?
        --
        Software is great!!!


        "John" wrote:
        [color=blue]
        > Hello,
        >
        > Why does the following code print "fail" instead of "123"
        > in the vc 2005 beta?
        >
        > Thanks
        >
        > -John
        >
        > #include "stdafx.h"
        >
        > #include <sstream>
        >
        > int _tmain(int argc, _TCHAR* argv[])
        > {
        > std::stringstre am ss("123,456");
        >
        > int x;
        >
        > ss >> x;
        >
        > if (ss.fail()) {
        > printf("fail");
        > } else {
        > printf("%d", x);
        > }
        >
        > return 0;
        > }
        >[/color]

        Comment

        • John Ky

          #5
          Re: Streams and commas

          The std::stringstre am class is in <sstream>

          -John

          Jason Murphy wrote:[color=blue]
          > why do you use "<sstream>" ?[/color]

          Comment

          Working...