cin line skipping

This is a discussion on cin line skipping within the C++ Programming forums, part of the General Programming Boards category; Whenever you use the cin function, after the user inputs, it automatically creates a newline. Im trying to make a ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    8

    Question cin line skipping

    Whenever you use the cin function, after the user inputs, it automatically creates a newline. Im trying to make a program, having the newline after every input really gets annoying

    Just wondering if there is a way to change that (without having to type in about 200 lines of code).

  2. #2
    unleashed alphaoide's Avatar
    Join Date
    Sep 2003
    Posts
    696
    I don't get it. Is this what you want to do?
    screen output:
    Enter an integer: 5 Enter another integer: 6
    In other words, after user input you want the next output printed on the same line???

  3. #3
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    >Just wondering if there is a way to change that
    This is outside the bounds of C++ and into the shell for your operating system. If you have nonlinear control of the screen (meaning you can do something like gotoxy) then you can go up one line after you get input and clear what was already there. But that's not portable, and you didn't say what kind of box you have.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  4. #4
    Registered User
    Join Date
    Sep 2003
    Posts
    8
    Win XP

    Im using Dev C++ Compiler/MSVC++

    And yeah, I want the next input to be on the same line as the previous. And i'm not familiar with gotoxy()

    //Edit
    I also want the previous input to still be there.

    So the first input:

    This is input

    Second input:

    This is input This is also input

    ^
    That is from the first input
    Last edited by Newbie Magic; 09-20-2003 at 11:19 AM.

  5. #5
    twm
    twm is offline
    root
    Join Date
    Sep 2003
    Posts
    232
    Okay, now I can help more. You can do something like this and have plenty of control:
    Code:
    #include <windows.h>
    #include <iostream>
    #include <iomanip>
    
    using namespace std;
    
    #define STDOUT GetStdHandle(STD_OUTPUT_HANDLE)
    
    void gotoxy (int x, int y) {
      COORD dwCursorPosition = { x, y };
      SetConsoleCursorPosition (STDOUT, dwCursorPosition);
    }
    
    int wherex ( ) {
      CONSOLE_SCREEN_BUFFER_INFO coninfo;
      GetConsoleScreenBufferInfo (STDOUT, &coninfo);
      return coninfo.dwCursorPosition.X;
    }
    
    int wherey ( ) {
      CONSOLE_SCREEN_BUFFER_INFO coninfo;
      GetConsoleScreenBufferInfo (STDOUT, &coninfo);
      return coninfo.dwCursorPosition.Y;
    }
    
    int main ( ) {
      int number;
    
      while (true) {
        cout<<"Enter a number: "<<flush;
        cin>> number;
        gotoxy(wherex(), wherey()-1);
        cout<< setw(70) << setfill(' ') <<""<<flush;
        gotoxy(0, wherey());
      }
    }
    >I also want the previous input to still be there.
    Just play with it and see what you can come up with.
    The information given in this message is known to work on FreeBSD 4.8 STABLE.
    *The above statement is false if I was too lazy to test it.*
    Please take note that I am not a technical writer, nor do I care to become one.
    If someone finds a mistake, gleaming error or typo, do me a favor...bite me.
    Don't assume that I'm ever entirely serious or entirely joking.

  6. #6
    Registered User
    Join Date
    Sep 2003
    Posts
    8
    Hey, thanks alot. I got the input on the same line as the prvious input and I got a better understanding of gotoxy()
    Last edited by Newbie Magic; 09-20-2003 at 11:43 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer and Polymorphism help.
    By Skyy in forum C++ Programming
    Replies: 29
    Last Post: 12-18-2008, 09:17 PM
  2. cin - reading empty line;
    By apacz in forum C++ Programming
    Replies: 6
    Last Post: 05-31-2007, 03:02 PM
  3. Very strange error...
    By Blackroot in forum C++ Programming
    Replies: 2
    Last Post: 12-14-2006, 01:37 AM
  4. Read only one line using seekg
    By RedZippo in forum C++ Programming
    Replies: 3
    Last Post: 03-31-2004, 11:10 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 02:27 PM

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