C ++: cin while cout

Well, I am writing chat in C ++ for use in linux terminal. I want to receive messages even while typing. mostly non-blocking cin. I managed to get this working by creating a thread. BUT the problem is that incoming messages and my input are combined together.

Is there a way to separate a string cinfrom other strings following from cout?

Sorry for my English.

+4
source share
2 answers

Is there a way to separate a string cinfrom other strings following from cout?

Yes, but it's a little complicated: you need to turn off the echo for the console and type in the characters entered by the end user as you type.

When you find an incoming message, you need to do the following three steps:

  • ,
  • , .

:

Friend: How are you?                        <== This is your friend prior message
You: > I am fi                              <== This is the text you've entered so far

, , :

Friend: How are you?                        <== This is your friend prior message
Friend: Are you coming to school tomorrow?  <== This is the new line that came in as the user was typing
You: > I am fi                              <== This is the text you've entered so far, re-printed again
+5

, ( ) , , cout .

.

+3

Source: https://habr.com/ru/post/1568994/


All Articles