-
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).
-
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???
-
>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.
-
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
-
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.
-
Hey, thanks alot. I got the input on the same line as the prvious input and I got a better understanding of gotoxy() :D