-
Notifications
You must be signed in to change notification settings - Fork 61
Guessing Game: Number input fails to produce Option int, instead produces Option none #48
Comments
This is the perfect place, thank you. Hmmm, strange. I tried the code and it worked for me. What platform are you on? |
I'm on 64-bit Windows 7, strange. |
Hm, I wonder if that's it. |
When I run this: use std::io::buffered::BufferedReader; use std::io; fn main() { println("Input: "); let mut reader = BufferedReader::new(io::stdin()); let input = reader.read_line().unwrap_or(~"nothing"); println!("{:?}", input.len()); } And only press enter, I get an output of |
Could it be that on windows it reads |
hmm, maybe. Edit: After looking around, I agree with Kimundi that window's use of http://static.rust-lang.org/doc/master/std/io/struct.BufferedReader.html |
After looking at http://adridu59.github.io/rust-tuts/tutorial/tutorial.html ,
This should work for both Windows, OS X and Linux systems, as it'll get rid of the http://static.rust-lang.org/doc/master/std/str/trait.StrSlice.html#tymethod.trim_right_chars |
This is going to be changed for 0.11. Please let me know if it still acts up with the new code. |
Running the Guessing Game program at the end of Chapter 11, it does not seem to recognise when I enter a number, instead always producing options of type none, I fixed this by changing
let num = from_str::<int>(input.slice_to(input.len() - 1));
to
let num = from_str::<int>(input.slice_to(input.len() - 2));
because I suspected that this method was trying to remove the
\n
from the end of the input string, and\n
would be two characters.Sorry, new to github so I believed this would be the best place to post about this, can this problem be confirmed?
The text was updated successfully, but these errors were encountered: