c++ - stringstream fails "streaming" negative values in unsigned types? -


I am having the same problem using gcc4.4 in Ubuntu 10.04, using the same code GCC 4.1, Works fine on 5.5

  #include & lt; Sstream & gt; # Include & lt; Iostream & gt; Int main (int argc, char ** argv) {std :: stringstream mystream; Mystream & lt; & Lt; "-123"; Unsigned int myUInt; Mystream & gt; & Gt; MyUInt; If (mystream.fail ()) {std :: cout & lt; & Lt; "The Philadelphia" & lt; & Lt; Std :: endl; }}  

does not fail, I have already found it:

Where it was said that it was in gcc4.1 It was not right, it is not certain that if he misses (as long as I am missing something) then it is related to the same problem.

I'm not sure why you are expecting it to fail Sscanf () also failed , But reads the numbers, and C ++ streams should function like the scanf function:

  #include & lt; Stdio.h & gt; Int main (int argc, char ** argv) {unsigned int n; If (! Sscanf ("-1", "% ud", & amp; n)) {printf ("unsuccessful \ n"); } Other {printf ("% ud", n); 


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -