
Print in same line
“Normal” Print
If you want to print with a line break at the end, it is pretty easy:
println!("Here is your message!"); println!("With {} placeholders too!", 1);
Which would output:
Here is your message! With 1 placeholders too!
Print in the same line
This needs some more increments.
- We need to import some things
- If we want to print it on the screen right away we need to flush the buffer which might be waiting to print.
use std::io::{stdout, Write}; print!("This should be "); stdout().flush().unwrap(); print!("in one line!"); stdout().flush().unwrap();
This should be in one line!
Of course, you can avoid the stdout flush repetition if you want. But for the purpose of demonstration I’ve repeated