|
||||||
| C and C++ C and C++ forum for discussing all forms of C except for C#. These languages are powerful low level languages used for creating Operating Systems, Device Drivers, compilers and much more. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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 |
| Sponsored Links |
|
|
|
|||||
|
Are you using strictly console, or are you using system API calls?
__________________
CodeCall Blog | CodeCall Wiki | Shareware | Linux Forum Programming is a branch of mathematics. |
|
|||
|
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.
|
|
|||
|
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! |
|
|||
|
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. |
| Sponsored Links |
|
|
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Lot's of errors | Jaan | PHP Forum | 11 | 03-08-2008 01:46 PM |
| HTML Basic Formatting | clookid | Tutorials | 14 | 03-06-2007 04:10 PM |
| WingedPanther | ........ | 2753.6 |
| Xav | ........ | 2704 |
| Brandon W | ........ | 1702.32 |
| John | ........ | 1207.73 |
| marwex89 | ........ | 1175.24 |
| morefood2001 | ........ | 966.05 |
| dcs | ........ | 655.75 |
| Steve.L | ........ | 475.59 |
| orjan | ........ | 418.58 |
| Aereshaa | ........ | 383.54 |
Goal: 100,000 Posts
Complete: 100%