-
Notifications
You must be signed in to change notification settings - Fork 1
/
2.rs
32 lines (26 loc) · 858 Bytes
/
2.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use std::io;
/// A program to read a line, without logical operators.
fn main()
{
let mut input = String::new();
let lim = 999;
let mut s = Vec::with_capacity(lim);
match io::stdin().read_line(&mut input) {
Ok (_bytes) => {
let mut i = 0;
for _c in input.chars() {
// Rust doesn't behave the same way as C
// error[E0369]: binary operation `+` cannot be applied to type `bool`
if i < lim-1 && _c != '\n' {
s.push(_c);
}
i += 1;
}
},
Err(_) => {
panic!("Unexpected error.");
}
}
// As we used a vec, we have to convert each position to a string, and collect everything
print!("{}\n", s.into_iter().map(|i| i.to_string()).collect::<String>());
}