+ 1
(C++) When an input is taken with "cin", the cursor go in a new line. Is it possibile to go back to the previous line?
I want to ask two input in the same line, in order to form two column, is it possible? And if yes, how?
1 Antwort
+ 2
A normal cin operation is stopped by any whitespace character, usually we use a newline.
Thus, if you do :
cin>>a>>b;
You can even input like this:
12 24 // Here I used a space instead of enter.
Now, to return back to the last line, there are 2 ways :
0) Use '\b', which returns to the last input character. This may not work at times, if it actually ignored your newline. You may also try '\r', which moves back in a similar way.
1) Use a cursor control function, and set the printing/reading position yourself.
Eg -
#include<windows.h>
void GOTO(int x, int y)
{
COORD cc = {x,y};
HANDLE in = GetStdHandle (STD_INPUT_HANDLE);
SetConsoleCursorPosition(in,cc);
}
// Now use the function above to set
// the position yourself.