Is there any way to force the print! / Println! to use the new line of Windows (CR LF)

I use Rust 1.9 on Windows 10. When playing with some code and comparing the result obtained from the standard output, I noticed that the output uses the Linux line ending with 0x0A (10, LF) and not the window 0x0D 0x0A (13 10, CR LF ) I tried the following:

println!("{} or {}  = {}", a, b, a | b);

print!("{} or {}  = {}\n", a, b, a | b);

Is there a way to do Windows line endings?

+4
source share
1 answer

If you check the implementationprintln! , this is 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 \nwith \r\n:

macro_rules! wprintln {
    ($fmt:expr) => (print!(concat!($fmt, "\r\n")));
    ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\r\n"), $($arg)*));
}
+7
source

All Articles