Lost Password?


Go Back   CodeCall Programming Forum > Software Development > C and C++

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.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-13-2008, 09:13 AM
mholt mholt is offline
Newbie
 
Join Date: Jan 2008
Posts: 27
Rep Power: 4
mholt is on a distinguished road
Post Moving a line of cin.getline down to the next available line (C++ console)?

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 04-14-2008, 12:53 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 3,376
Last Blog:
wxWidgets is NOT code ...
Rep Power: 37
WingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to beholdWingedPanther is a splendid one to behold
Default Re: Moving a line of cin.getline down to the next available line (C++ console)?

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-15-2008, 06:04 PM
G_Morgan G_Morgan is offline
Guru
 
Join Date: Oct 2007
Age: 24
Posts: 506
Last Blog:
Just over the next hil...
Rep Power: 10
G_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura about
Default Re: Moving a line of cin.getline down to the next available line (C++ console)?

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 04-16-2008, 07:25 PM
mholt mholt is offline
Newbie
 
Join Date: Jan 2008
Posts: 27
Rep Power: 4
mholt is on a distinguished road
Default Re: Moving a line of cin.getline down to the next available line (C++ console)?

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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 04-16-2008, 08:28 PM
G_Morgan G_Morgan is offline
Guru
 
Join Date: Oct 2007
Age: 24
Posts: 506
Last Blog:
Just over the next hil...
Rep Power: 10
G_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura aboutG_Morgan has a spectacular aura about
Default Re: Moving a line of cin.getline down to the next available line (C++ console)?

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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 04-20-2008, 03:12 PM
mholt mholt is offline
Newbie
 
Join Date: Jan 2008
Posts: 27
Rep Power: 4
mholt is on a distinguished road
Default Re: Moving a line of cin.getline down to the next available line (C++ console)?

Okay. Thank you for this information! It's apparent that I should find a different way to prevent this problem. Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

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


All times are GMT -5. The time now is 02:36 PM.

Contest Stats

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

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 100%

Ads