Simple Serial Input Output Question

Hi there. I am working on a project which I have to re-design it a little bit.
I was working on the simple in- and outputs of the serial monitor and a question raised in my mind:
Why do I get such a "late" response from the Serial Monitor when I'm typing an input.

Refering to my simple code:

#include <String.h>

void setup() {
  Serial.begin(9600);
  
}

void loop() {
  String read_string = Serial.readString();
  Serial.println("Input: ");
  delay(8000);
  Serial.println("Output: "); Serial.println(read_string);
  delay(3000);

}

When I start this, first the Serial Monitor asks me for an input. So I type in something like "abc". But why isn't "abc" displayed at the output right away? It's something like this:

Input:       //Here I typed "abc" in the input field of the serial monitor 
Output:    // But instead that it's shown here

Input: 
Output:   //It's displayed 1 output after I typed in.
abc

Why is that so?
To give an example for a c++ code:

string typesomething;

cout << "Type something: ";           
cin >> typesomething;               //Here I type in "abc"
cout << "you typed: " << typesomething << endl;     //And "abc" is displayed right after I typed it in

But why doesn't the same apply to the serial monitor?

why isn't "abc" displayed at the output right away?

Because you don't print it until after you have wasted 8 seconds between printing "Input: " and "Output: "

Serial.readString(); does what its name suggests, ie it reads a String. It does not print what you entered

why doesn't the same apply to the serial monitor?

It does

Try this

#include <String.h>

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  Serial.println("Enter some text");
  String read_string = Serial.readString();
  Serial.print("You entered: ");
  Serial.println(read_string);
  Serial.println();
  delay(2000);
}

@OP

Let us calculate (to a reasonable approximation) how much time delay you encounter to see your inputted message ("abc") back on the Serial Monitor.

1. Maximum (default) timeout-time of Serial.readString(); method is 1000 ms (see Serial.setTimeout()). You must enter your message in the InputBox of Serial Monitor within this timeout time period.

2. Time needed by the message "abc" to arrive from Serial Monitor/PC to the UNO is about 3x(1/9600)*10 = 3.12 ms.

3. You are sending the prompt message "Input: " to Serial Monitor. It takes about 7x(1/9600)*10 = 7.29 ms.

4. You have inserted 8000 ms time delay by calling delay() function.

5. You are sending the prompt message "Output: " to Serial Monitor. It takes about 8x(1/9600)*10 = 8.33 ms.

6. Time needed by the message "abc" to reach from UNO to Serial Monitor/PC about 3x(1/9600)*10 = 3.12 ms.

Total time delay = 1+ 3.12 + 7.29 + 8000 + 8.33 + 3.12 ~= 9022 ms

Now, you know the various contributing components for the total delay.

Have a look at the examples in Serial Input Basics - simple reliable ways to receive data.

...R

The thing is that I don't want always the text like "Enter your text:" to show up. That's what I choose the delay()-function for. What I want to accomplish is, that the text "Enter your text:" is displayed until I enter some text.

Normally the output on the serial monitor would something be like that:

Enter some text:
Enter some text:
Enter some text:
Enter some text:
Enter some text:

It's appearing like every second. But what I want is something like:

Enter some text:    //Wait until I entered some text

That's why I used the delay()-funtion to give me some time to make an input

Use a boolean flag initialised as true.

Check it in a "if" and only print your prompt if it's true. Then when you print the prompt, immediately set it false so next time round loop() it won't print.

Then when text is entered, set it true for next time.

SchnoppDog:
The thing is that I don't want always the text like "Enter your text:" to show up.

Have a look at the simple user input example in Planning and Implementing a Program

...R