I was experimenting with strings and the library std::io
, so I tried to make a program that would print all the characters of a string to the screen one by one:
use std::io;
fn main() {
let mut expresion = String::new();
io::stdin()
.read_line(&mut expresion)
.expect("No se pudo leer la linea");
if expresion.trim() == "exit" {
print!("el plan ha fallado con exito");
}
for i in 0..expresion.len(){
println!("{}", &expresion[i-1..i] );
}
}
I don't get any syntax errors, the program compiles without problem, but at runtime, I get the following error:
"thread 'main' panicked at 'attempt to subtract with overflow', src/main.rs:16:35"