@@ -75,14 +75,14 @@ Let's get to it! The first thing we need to do for our guessing game is
7575allow our player to input a guess. Put this in your ` src/main.rs ` :
7676
7777``` {rust,no_run}
78- use std::io ;
78+ use std::old_io ;
7979
8080fn main() {
8181 println!("Guess the number!");
8282
8383 println!("Please input your guess.");
8484
85- let input = io ::stdin().read_line()
85+ let input = old_io ::stdin().read_line()
8686 .ok()
8787 .expect("Failed to read line");
8888
@@ -121,7 +121,7 @@ explanatory text, and then an example. Let's try to modify our code to add in th
121121` random ` function and see what happens:
122122
123123``` {rust,ignore}
124- use std::io ;
124+ use std::old_io ;
125125use std::rand;
126126
127127fn main() {
@@ -133,7 +133,7 @@ fn main() {
133133
134134 println!("Please input your guess.");
135135
136- let input = io ::stdin().read_line()
136+ let input = old_io ::stdin().read_line()
137137 .ok()
138138 .expect("Failed to read line");
139139
@@ -180,7 +180,7 @@ This says "please give me a random `i32` value." We can change our code to use
180180this hint:
181181
182182``` {rust,no_run}
183- use std::io ;
183+ use std::old_io ;
184184use std::rand;
185185
186186fn main() {
@@ -192,7 +192,7 @@ fn main() {
192192
193193 println!("Please input your guess.");
194194
195- let input = io ::stdin().read_line()
195+ let input = old_io ::stdin().read_line()
196196 .ok()
197197 .expect("Failed to read line");
198198
@@ -233,7 +233,7 @@ unsigned integer approach. If we want a random positive number, we should ask fo
233233a random positive number. Our code looks like this now:
234234
235235``` {rust,no_run}
236- use std::io ;
236+ use std::old_io ;
237237use std::rand;
238238
239239fn main() {
@@ -245,7 +245,7 @@ fn main() {
245245
246246 println!("Please input your guess.");
247247
248- let input = io ::stdin().read_line()
248+ let input = old_io ::stdin().read_line()
249249 .ok()
250250 .expect("Failed to read line");
251251
@@ -276,7 +276,7 @@ two numbers. Let's add that in, along with a `match` statement to compare our
276276guess to the secret number:
277277
278278``` {rust,ignore}
279- use std::io ;
279+ use std::old_io ;
280280use std::rand;
281281use std::cmp::Ordering;
282282
@@ -289,7 +289,7 @@ fn main() {
289289
290290 println!("Please input your guess.");
291291
292- let input = io ::stdin().read_line()
292+ let input = old_io ::stdin().read_line()
293293 .ok()
294294 .expect("Failed to read line");
295295
@@ -331,7 +331,7 @@ but we've given it unsigned integers. In this case, the fix is easy, because
331331we wrote the `cmp` function! Let' s change it to take ` u32` s:
332332
333333` ` ` {rust,ignore}
334- use std::io ;
334+ use std::old_io ;
335335use std::rand;
336336use std::cmp::Ordering;
337337
@@ -344,7 +344,7 @@ fn main() {
344344
345345 println! (" Please input your guess." );
346346
347- let input = io ::stdin().read_line ()
347+ let input = old_io ::stdin().read_line ()
348348 .ok ()
349349 .expect(" Failed to read line" );
350350
@@ -397,7 +397,7 @@ Anyway, we have a `String`, but we need a `u32`. What to do? Well, there's
397397a function for that:
398398
399399` ` ` {rust,ignore}
400- let input = io ::stdin().read_line ()
400+ let input = old_io ::stdin().read_line ()
401401 .ok ()
402402 .expect(" Failed to read line" );
403403let input_num: Option< u32> = input.parse ();
@@ -429,7 +429,7 @@ let input_num: Option<u32> = "5".parse(); // input_num: Option<u32>
429429Anyway, with us now converting our input to a number, our code looks like this:
430430
431431` ` ` {rust,ignore}
432- use std::io ;
432+ use std::old_io ;
433433use std::rand;
434434use std::cmp::Ordering;
435435
@@ -442,7 +442,7 @@ fn main() {
442442
443443 println! (" Please input your guess." );
444444
445- let input = io ::stdin().read_line ()
445+ let input = old_io ::stdin().read_line ()
446446 .ok ()
447447 .expect(" Failed to read line" );
448448 let input_num: Option< u32> = input.parse ();
@@ -479,7 +479,7 @@ need to unwrap the Option. If you remember from before, `match` is a great way
479479to do that. Try this code:
480480
481481```{rust,no_run}
482- use std::io ;
482+ use std::old_io ;
483483use std::rand;
484484use std::cmp::Ordering;
485485
@@ -492,7 +492,7 @@ fn main() {
492492
493493 println!("Please input your guess.");
494494
495- let input = io ::stdin().read_line()
495+ let input = old_io ::stdin().read_line()
496496 .ok()
497497 .expect("Failed to read line");
498498 let input_num: Option<u32> = input.parse();
@@ -546,7 +546,7 @@ method we can use defined on them: `trim()`. One small modification, and our
546546code looks like this:
547547
548548```{rust,no_run}
549- use std::io ;
549+ use std::old_io ;
550550use std::rand;
551551use std::cmp::Ordering;
552552
@@ -559,7 +559,7 @@ fn main() {
559559
560560 println!("Please input your guess.");
561561
562- let input = io ::stdin().read_line()
562+ let input = old_io ::stdin().read_line()
563563 .ok()
564564 .expect("Failed to read line");
565565 let input_num: Option<u32> = input.trim().parse();
@@ -620,7 +620,7 @@ As we already discussed, the `loop` keyword gives us an infinite loop.
620620Let' s add that in:
621621
622622` ` ` {rust,no_run}
623- use std::io ;
623+ use std::old_io ;
624624use std::rand;
625625use std::cmp::Ordering;
626626
@@ -635,7 +635,7 @@ fn main() {
635635
636636 println! (" Please input your guess." );
637637
638- let input = io ::stdin().read_line ()
638+ let input = old_io ::stdin().read_line ()
639639 .ok ()
640640 .expect(" Failed to read line" );
641641 let input_num: Option< u32> = input.trim().parse ();
@@ -696,7 +696,7 @@ Ha! `quit` actually quits. As does any other non-number input. Well, this is
696696suboptimal to say the least. First, let' s actually quit when you win the game:
697697
698698```{rust,no_run}
699- use std::io ;
699+ use std::old_io ;
700700use std::rand;
701701use std::cmp::Ordering;
702702
@@ -711,7 +711,7 @@ fn main() {
711711
712712 println!("Please input your guess.");
713713
714- let input = io ::stdin().read_line()
714+ let input = old_io ::stdin().read_line()
715715 .ok()
716716 .expect("Failed to read line");
717717 let input_num: Option<u32> = input.trim().parse();
@@ -752,7 +752,7 @@ we don't want to quit, we just want to ignore it. Change that `return` to
752752
753753
754754```{rust,no_run}
755- use std::io ;
755+ use std::old_io ;
756756use std::rand;
757757use std::cmp::Ordering;
758758
@@ -767,7 +767,7 @@ fn main() {
767767
768768 println!("Please input your guess.");
769769
770- let input = io ::stdin().read_line()
770+ let input = old_io ::stdin().read_line()
771771 .ok()
772772 .expect("Failed to read line");
773773 let input_num: Option<u32> = input.trim().parse();
@@ -831,7 +831,7 @@ think of what it is? That's right, we don't want to print out the secret number.
831831It was good for testing, but it kind of ruins the game. Here' s our final source:
832832
833833```{rust,no_run}
834- use std::io ;
834+ use std::old_io ;
835835use std::rand;
836836use std::cmp::Ordering;
837837
@@ -844,7 +844,7 @@ fn main() {
844844
845845 println!("Please input your guess.");
846846
847- let input = io ::stdin().read_line()
847+ let input = old_io ::stdin().read_line()
848848 .ok()
849849 .expect("Failed to read line");
850850 let input_num: Option<u32> = input.trim().parse();
0 commit comments