-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
unordered console output #114747
Comments
@Leandrys-Osorio On the same platform, I get the following output:
The detail here is that the buffer is only flushed by |
Sorry, I don't understand to much but I wonder you want this information: Libc = "0.2.147" About kernel(I suppose it's my Linux kernel) = 6.2.6 And I'm sure about the output... I have copied the text snippets, and check your exclamation mark, would it be at the next line of the variable value? (check your output) |
glibc is a file on your system, usually it is located at My output is exactly copied from my terminal. |
Are you using a different shell, like the one in VS Code, or emacs, or zsh or fish or nushell? |
Basically, if you can type |
Are you sure this is the code you're actually executing? The output you got would be expected lines 4-7 were:
Notice the swapping of In this case it's expected that the second This happens for performance reasons, but you can control this behaviour by inserting a manual "flush" to stdout (i.e. sending whatever is in the buffer to it immediately) right after the print!("Please, input your guess ");
// `flush` is a method of the `std::io::Write` trait, so bring it into scope.
use std::io::Write;
std::io::stdout().flush().expect("Couldn't flush to stdout"); |
i only found this with "whereis" command: and i was using bash in vscode. my env output: |
do you consider that for the use of a simple print i need to use this? sorry but i consider it is a bug, i have never seen any lang that can not show the output correctly, the best part is it ask for the user entry and later show the placeholder... sorry i don't understand it |
The Rust issue tracker is not a support forum. Rust has an official forum: https://users.rust-lang.org/ a subreddit: https://www.reddit.com/r/rust/ a community Discord: https://discord.com/invite/rust-lang-community and an official Discord: https://discord.com/invite/rust-lang. Those are all better places to seek help in using Rust than the issue tracker. The code you posted in this issue description does not reproduce the problem. I can say that with total certainty because it doesn't compile, and therefore it is very tempting to explain what you are reporting here as incorrect transcription of what's in your editor or pasting an old version of your code. This program does produce the behavior you reported, but using different code: use std::io;
use std::io::Read;
fn main() {
// vars
let mut guess = String::new();
println!("Guess the number!");
// take user input
print!("Please, input your guess ");
io::stdin()
.read_line(&mut guess)
.expect("failed to read line :(");
println!("You guessed: {}!", guess);
} I suggest you double-check that you have code that reproduces the behavior you find problematic, then start a conversation at any of the alternative venues I suggested. You will almost certainly find them more responsive. |
I do not consider it professional to treat a person who is trying to help in a certain way with what little they know, if I made this contribution it is because at least I have worked with other languages and I know that this is not a normal way out since it is not correct that first ask for the user input and after the input is entered the "enter a number" message is displayed, but don't worry even if your way of responding to my innocent intention to help is bad I don't plan to take it much more than an answer . If I wanted help from someone to tell me how to write code easily I would have asked anywhere since a console program is something that anyone can understand.
I do not consider it professional to treat a person who is trying to help in a certain way with what little they know, if I made this contribution it is because at least I have worked with other languages and I know that this is not a normal way out since it is not correct that first ask for the user input and after the input is entered the "enter a number" message is displayed, but don't worry even if your way of responding to my innocent intention to help is bad I don't plan to take it much more than an answer . If I wanted help from someone to tell me how to write code easily I would have asked anywhere since a console program is something that anyone can understand. |
@Leandrys-Osorio There are very few explanations for your problem, either
...note that I listed these in order of decreasing probability. We are not trying to be rude, but it can be very challenging to sort out a problem if you modify the reported code in any way. Nonetheless, I benignly assumed that your added line numbers could be removed, and that imports could be added, and everything could be wrapped in We have also mentioned write-flushing. You say a console program is something anyone can understand, but many people are not aware of streams, buffers, and flushing. Thus they do not necessarily understand the documentation for print! and println!. Rust quite deliberately offers fairly low-level control of many things, including printing. You mention you have not encountered any difficulty with other programming languages, but most languages deliberately obfuscate and remove control of what is actually quite a complex process. |
Looks like this was discussed extensively in #23818 |
Thank you very much, at least although I don't think you're exactly right, your answer seems a bit nicer, thanks again for assuming that the numbers in front of the code is just a placeholder put on purpose, obviously no code can compile having numbers in front of it. In any case, my concern was that it asked me to enter the data first and then it showed the text asking me to enter the data. But I am not one to tell you whether to believe my report or not. Thank you again and have a great day |
I tried this code:
I expected to see this process:
Instead, the process is weird, i have done this exercise in another programming languages and i have never seen this order:
Meta
rustc --version --verbose
:I'm a novice using rust, but i consider it is not correct, this may help others novices.
The text was updated successfully, but these errors were encountered: