8bit 0 Report post Posted February 19, 2005 What happens if I assigned a string to an integer? Because I used a try statement for it and the catch didn't get invoked! Does it just assign a to 0!? Share this post Link to post Share on other sites
leiaah 0 Report post Posted February 19, 2005 What happens if I assigned a string to an integer? Because I used a try statement for it and the catch didn't get invoked! Does it just assign a to 0!? 51835[/snapback] I suppose you're using Java. You can easily assign a String to an Integer by using parseInt. String s = "777"; int x = Integer.parseInt(s); Share this post Link to post Share on other sites
osknockout 0 Report post Posted February 19, 2005 I suppose you're using Java.You can easily assign a String to an Integer by using parseInt.String s = "777";int x = Integer.parseInt(s);Ok, let's think about this. This is the C/C++ programming forum. What 8bit just said makes perfect sense in C++ (exception handling), so it's probably not Java Just a thought leeiah.What happens if I assigned a string to an integer? Because I used a try statement for it and the catch didn't get invoked! Does it just assign a to 0!?Could you please state what compiler you're using (version also) and perhaps the source code? Normally that would not even compile with what I'm using. Share this post Link to post Share on other sites
dexter 0 Report post Posted February 21, 2005 I can't see it being an accidental thing, as if it were, without casting it, the compiler would complain.So, if you did cast it... like int x = (int)"777"; then it wouldn't be caught because it wouldn't fail. It wouldn't be correct, but it definately wouldn't fail...I'm still trying to fathom the need for crossing types in this case... if you want to assign a the value in a string to an int, you'd just use atoi().I'm really interested to see why this is necessary. More details would be nice. Share this post Link to post Share on other sites
8bit 0 Report post Posted February 24, 2005 I used MingW and wrote the source with: CONText...but I might be able to find out the problem. And uh...leeiah this is a C/C++ board...why would I post Java stuff here? Very hard question, eh? Share this post Link to post Share on other sites
osknockout 0 Report post Posted February 24, 2005 I mean source code as in what you wrote...MingW eh? I only use plain old gcc, so I can't help you with that one. Very hard question, eh?Well yes and no, see, it's not defined in the standard as to whether or not you can do so. Why don't you compile it and give it a try? We're all stumped. Share this post Link to post Share on other sites