我找到的所有关于刷新的文档都表明,正确的刷新stdout的方法如下:
std::io::stdout().flush().expect("some error message");
这导致
no method named flush found for type std::io::Stdout in the current scope
我做错了什么?
我找到的所有关于刷新的文档都表明,正确的刷新stdout的方法如下:
std::io::stdout().flush().expect("some error message");
这导致
no method named flush found for type std::io::Stdout in the current scope
我做错了什么?
您需要为Stdout
导入实现flush
方法的trait.
根据文件:
因此:
use std::io::Write; // <--- bring the trait into scope
fn main() {
std::io::stdout().flush().expect("some error message");
}