I am using Rust 1.9 on Windows 10. When playing with some code and comparing the result captured from standard output, I noticed that output uses a Linux line ending 0x0A (10, LF) rather than windows 0x0D 0x0A (13 10, CR LF). I tried following:
println!("{} or {} = {}", a, b, a | b);
print!("{} or {} = {}\n", a, b, a | b);
Is there a way to force Windows line endings?
If you check out the implementation of println!
, it's pretty straight-forward:
macro_rules! println {
($fmt:expr) => (print!(concat!($fmt, "\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*));
}
You can copy-paste-modify this to replace \n
with \r\n
:
macro_rules! wprintln {
($fmt:expr) => (print!(concat!($fmt, "\r\n")));
($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\r\n"), $($arg)*));
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With