N
N
Nexeon2016-09-24 16:31:07
C++ / C#
Nexeon, 2016-09-24 16:31:07

How to implement parallel text input and output?

I'm doing a chat. In the following code, the message of the interlocutor is displayed only after I have entered text into the lines

while(true) {
 string s; //мое сообщение
 cin >> s; //или getline(cin, s)
 cout << /* текст сообщения собеседника */;
}

How can I make other people's messages appear coutin the console at the same time as cinmy message is entered? In which direction of multithreading is it worth digging?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
O
Oleg Tsilyurik, 2016-09-24
@MrNexeon

How can I make other people's messages cout to the console at the same time as cin my message?

1. Make 2 threads.
2. Use byte-by-byte input and output (cyclic polling).
PS Only cin/cout for "chat"... ? somehow funny ... a good anecdote, plus.

R
romy4, 2016-09-24
@romy4

look towards epoll

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question