Thread: How to Input without Breaking line in a console?

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    162

    How to Input without Breaking the Line in a console?

    Hi, all... sorry me again

    How do you request a user to input a string like "cin >> x;" without breaking the current line where the input took place, when the user hits the Enter key? So that when you output a string to the console like "cout << x;", the output will be on the same line where the user inputed last.
    Last edited by Aidman; 03-11-2003 at 02:00 PM.
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  2. #2
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    I might be, and probably am, wrong here, but i think cin clears the buffer and therefore causes the line drop...

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    So what should I do to prevent this? or are there any other function for input that doesn't break the line?
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  4. #4
    Registered User
    Join Date
    Feb 2003
    Posts
    34
    Try '\r'
    This should prevent advancement to the next line

  5. #5
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    In a cout line yes, but i dont see how that will work on a cin line.

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    so what should I do? please help
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  7. #7
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Use gotoxy() or a variant of your compiler to move a line back up,
    You do need some recording of what's going on on the screen
    for this though.
    --

  8. #8
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    I am using VC++. Could you explain how I can keep a record of whats going on on the screen? and is it possible to get the current position of input or output?
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  9. #9
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Just create a 2D character array, And when you want to print
    something write it to that array, And then loop trough the array
    and print everything on the screen, This way you'll create some
    kind of screen buffer.
    --

  10. #10
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    but what if some text is already displayed on the screen/console before my program started and I don't want to clear the screen?
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

  11. #11
    Registered User
    Join Date
    Sep 2002
    Posts
    1,640
    Originally posted by Aidman
    but what if some text is already displayed on the screen/console before my program started
    I'm not following you here, What do you mean? When you
    start a new program, You get a new empty console.
    --

  12. #12
    Registered User
    Join Date
    Dec 2002
    Posts
    162
    Say you made a program that records all text you output to the console screen with "cout << x;". Now lets say you compiled the program and named it "record.exe". But what if you open a new console window by running the "command.exe" and from there run your program. Then there are already some lines wiritten on the console that your program hasn't recorded, like "c:\>command.exe". However if you would be able to know what position your next text with "cout << x:" will be printed on in the console then you could know where to move to by the function you said, gotoxy(). But what header do you need for this function gotoxy()? and how do you get the current position of the text you will output next time?
    We haven't inherited Earth from our parents; instead we have borrowed her from our children - old Indian saying.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  2. Controlling console command window input
    By DanFraser in forum C# Programming
    Replies: 0
    Last Post: 11-27-2007, 10:34 AM
  3. Console application - input handling
    By Something in forum C++ Programming
    Replies: 4
    Last Post: 06-09-2007, 02:19 PM
  4. reading an input line using scanf() with %c
    By linucksrox in forum C Programming
    Replies: 6
    Last Post: 04-04-2004, 03:10 PM
  5. How to put a Char into the Input buffer of a console?
    By Aidman in forum C++ Programming
    Replies: 10
    Last Post: 03-09-2003, 10:05 AM