Function std::io::stdout 1.0.0[−][src]
Expand description
为当前进程的标准输出创建一个新的句柄。
返回的每个句柄都是对共享缓冲区的引用,该缓冲区的访问通过互斥锁进行同步。
如果需要对锁定进行更明确的控制,请参见 Stdout::lock
方法。
Note: Windows 可移植性注意事项
在控制台中操作时,此流的 Windows 实现不支持非 UTF-8 字节序列。
尝试写入无效的 UTF-8 字节将返回错误。
Examples
使用隐式同步:
use std::io::{self, Write};
fn main() -> io::Result<()> {
io::stdout().write_all(b"hello world")?;
Ok(())
}
Run使用显式同步:
use std::io::{self, Write};
fn main() -> io::Result<()> {
let stdout = io::stdout();
let mut handle = stdout.lock();
handle.write_all(b"hello world")?;
Ok(())
}
Run