Overriding Cin with Cout

This is a discussion on Overriding Cin with Cout within the C++ Programming forums, part of the General Programming Boards category; I need some way to replace a Cin with something that prints to the dos screen(cout) before the user actually ...

  1. #1
    Registered User
    Join Date
    Oct 2005
    Posts
    2

    Overriding Cin with Cout

    I need some way to replace a Cin with something that prints to the dos screen(cout) before the user actually enters anything into the Cin. I finally got multi-threading to work, but now whenever I want it to display something with thread 2, it waits for the person to enter something for the Cin from thread 1 rather than just displaying it immediately. I've done some testing, so I'm sure the multi-threading is working, its just this Cin problem. Thanks for any help.

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    IIRC cin and cout is not thread safe. Have you tried just flushing the buffer?

  3. #3
    Unregistered User
    Join Date
    Sep 2005
    Location
    Antarctica
    Posts
    341
    yea if you want cin and cout to behave on threads you need to synchronize the access to them, use critical sections or a semaphore or something.

  4. #4
    Registered User
    Join Date
    Oct 2005
    Posts
    2
    err I just started programming a couple days ago, so I don't know how to do that stuff. Is there any other relatively easy ways to print text and to get input without those? Also you talked about flushing the buffer, how would I do that?

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Wait, you just started programming a few days again and you are already making multi-threaded applications? I think you need to spend some time on the basics.

  6. #6
    Registered User
    Join Date
    Sep 2005
    Posts
    241
    no i think he means kindof a question and answer type of thing

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. CIN Input count question?
    By kamran in forum C++ Programming
    Replies: 5
    Last Post: 10-24-2006, 04:06 PM
  2. Binary I/O with cin and cout
    By The Urchin in forum C++ Programming
    Replies: 4
    Last Post: 10-24-2006, 12:47 PM
  3. Problem Calling Destructor, and prob with cin.
    By imortal in forum C++ Programming
    Replies: 2
    Last Post: 10-10-2003, 09:29 AM
  4. Cin & Cout VS. Scanf & Printf
    By MatriXxX in forum C Programming
    Replies: 19
    Last Post: 08-08-2003, 11:47 AM
  5. Redirecting cout stream
    By Arrow Mk84 in forum C++ Programming
    Replies: 1
    Last Post: 10-08-2002, 04:17 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21