Hi,
I have a case in which the user is presented with a cursor to type input in a console window (in C++ with Dev-Cpp) - but a couple threads are running at the same time. These threads respond to events by "cout"ing text to the console on its own line.
So I need a way to have the current line with the cin.getline stuff move DOWN to the next available line, then put the text from the other threads above it. Oh, and if the user has typed something, that text should not be lost; the user should be able to just continue typing.
Is there a way to do this? What methods might you recommend?
Thanks,
-Matt
Moving a line of cin.getline down to the next available line (C++ console)?
Started by mholt, Apr 13 2008 05:13 AM
5 replies to this topic
#1
Posted 13 April 2008 - 05:13 AM
|
|
|
#2
Posted 14 April 2008 - 08:53 AM
Are you using strictly console, or are you using system API calls?
#3
Posted 15 April 2008 - 02:04 PM
This is probably going to be complicated. What you'll need to do is create a thread safe console driver with your own API (i.e. you'll have to set up your own input buffers and write to the console yourself using system API's). You probably aren't going to be able to achieve what you want through the standard functions, C++ wasn't designed with threading in mind and the standard functions reflect this.
#4
Posted 16 April 2008 - 03:25 PM
Ah yes, sorry I should have clarified. I'm using the standard Windows API (no .NET stuff).
If it really is that complicated, could somebody suggest an alternative? It's a utility I'm writing that is sort of a "chat" program (except it's all encrypted, plus some other little features I included), so I basically need to "reserve" a space in the console for the user to type messages without being interrupted by an incoming message. (using Winsock)
I really want to avoid a GUI. Is there a way to do this? I'm still rather new, I think, and thinking out-of-the-box like this is still a bit beyond me.
Cheers!
If it really is that complicated, could somebody suggest an alternative? It's a utility I'm writing that is sort of a "chat" program (except it's all encrypted, plus some other little features I included), so I basically need to "reserve" a space in the console for the user to type messages without being interrupted by an incoming message. (using Winsock)
I really want to avoid a GUI. Is there a way to do this? I'm still rather new, I think, and thinking out-of-the-box like this is still a bit beyond me.
Cheers!
#5
Posted 16 April 2008 - 04:28 PM
Offhand I can't think of any. Dealing with CLI interaction with threaded programs is not something I've ever dealt with (at least I've never allowed more than one thread access to it).
This is the problem with threading. You need to be able to control access to a shared resource and AFAIK there is no way to achieve this with the basic iostreams library. Do these other messages have to go to the CLI? Can you divert them to a different stream like stderr?
Otherwise I think you will have to program the console directly rather than using iostream. Essentially I'd setup a console driver where a buffer takes up the bottom line of the console and the rest forms a message list. Your messages would be diverted to list and avoid your input buffer altogether.
This is the problem with threading. You need to be able to control access to a shared resource and AFAIK there is no way to achieve this with the basic iostreams library. Do these other messages have to go to the CLI? Can you divert them to a different stream like stderr?
Otherwise I think you will have to program the console directly rather than using iostream. Essentially I'd setup a console driver where a buffer takes up the bottom line of the console and the rest forms a message list. Your messages would be diverted to list and avoid your input buffer altogether.
#6
Posted 20 April 2008 - 11:12 AM
Okay. Thank you for this information! It's apparent that I should find a different way to prevent this problem. Thanks!


Sign In
Create Account


Back to top









