Giter Site home page Giter Site logo

cfireworks.github.io's People

Contributors

cfireworks avatar

Watchers

 avatar  avatar

cfireworks.github.io's Issues

Rust中print不换行无法即时输出问题

问题描述

ust语言用println!宏打印一行信息,用print!宏打印信息,行尾不加换行符。

但是用print!宏打印信息后,并不会立即显示。

比如,下面代码会先等待用户输入,然后再打印消息。

use std::io;

fn main() {
    print!("Please input your guess:");
    let mut guess = String::new();    
    println!("You guessed: {}", guess);
}

解决方法

rust标准输出是行缓冲的,只有到行尾才显示,如果想不到行尾直接显示怎么办?答案是手动刷新,方法如下:

use std::io;

fn main() {
    print!("Please input your guess:");
    io::stdout().flush().expect("Flush err");
    let mut guess = String::new();    
    println!("You guessed: {}", guess);
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.