相关疑难解决方法(0)

写入Rust中的文件或标准输出

我正在学习Rust,我有点难过.

我正在尝试为用户提供将输出写入stdout或提供的文件名的选项.

我开始与那正是使用给出的示例代码extra::getopts位于这里.从那里,在do_work函数中,我正在尝试这样做:

use std::io::stdio::stdout;
use std::io::buffered::BufferedWriter;

fn do_work( input: &str, out: Option<~str> ) {
    println!( "Input:  {}", input );
    println!( "Output: {}", match out {
        Some(x) => x,
        None    => ~"Using stdout"
    } );
    let out_writer = BufferedWriter::new( match out {
        // I know that unwrap is frowned upon, 
        // but for now I don't want to deal with the Option.
        Some(x) => File::create( &Path::new( x ) ).unwrap(),
        None    => stdout()
    } ); …
Run Code Online (Sandbox Code Playgroud)

file stdio rust

6
推荐指数
2
解决办法
3672
查看次数

标签 统计

file ×1

rust ×1

stdio ×1