如:
let mut a : usize = 0xFF;
a += -1; // -1 may be from other variable, so there can't be a -= 1;
println!("{}", a);
Run Code Online (Sandbox Code Playgroud)
输出是:
let mut a : usize = 0xFF;
a += -1; // -1 may be from other variable, so there can't be a -= 1;
println!("{}", a);
Run Code Online (Sandbox Code Playgroud)
反正?
use std::fmt::Write;
use std::fs::File;
use std::io::Write;
fn main() -> std::io::Result<()> {
let mut p = String::new();
(1..6).for_each(|n| {
write!(&mut p, "{},", n);
});
let mut file = File::create("a.csv")?;
file.write_all(p.as_bytes())?;
Ok(())
}
Run Code Online (Sandbox Code Playgroud)
编译时出现错误:
use std::fmt::Write;
use std::fs::File;
use std::io::Write;
fn main() -> std::io::Result<()> {
let mut p = String::new();
(1..6).for_each(|n| {
write!(&mut p, "{},", n);
});
let mut file = File::create("a.csv")?;
file.write_all(p.as_bytes())?;
Ok(())
}
Run Code Online (Sandbox Code Playgroud)
和警告:
error[E0599]: no method named `write_all` found for type `std::fs::File` in the current scope
Run Code Online (Sandbox Code Playgroud)
如何将数组连接到字符串并写入文件?