I'm trying to figure out how to write a string to a file. The following gives me the error format argument must be a string literal:
use std::fs::File;
use std::io::{Error, Write};
fn main() -> Result<(), Error> {
let path = "results.txt";
let mut output = File::create(path)?;
let line = println!("{}", "hello");
write!(output, line);
}
How can I write to a file from a string variable? If I change the follow line it works, but I can't figure out how to write to a file if the string is in a variable.
write!(output, "foo,bar,baz");