-
Preventing Newline
Hi, i'm trying to output a character in the very bottom of the console screen, far right hand side. However, the cursor keeps going onto a new line once the character has been placed in the corner. Is there any format specifier that can be included within the cout statement to prevent this from happening?
Thanks.
-
maybe if you set the width to 80 and right aligned
EDIT: ie cout.width=80;
-
Thanks, it still made no difference. The cursor still went onto the next line.
-
I have no idea how to prevent it from going to a newline at the end of the screen... you could do it with WinAPI calls, but I don't think that's what you want
cout.setw(80)
might help, depending on what you are trying to do
-
not 100% sure this will work but it should. print a backspace immediately after whatever your printing....
gotoxy(bottom right corner)
cout<<"your thing here\b";
might do the trick.
-
Code:
// Sets the cursor position
void SetCursor(int x, int y)
{
HANDLE hConsoleOutput;
COORD dwCursorPosition;
// go to the specified location
dwCursorPosition.X = x;
dwCursorPosition.Y = y;
hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hConsoleOutput,dwCursorPosition);
}
int main()
{
SetCursor(80,24);
cout << "X";
SetCursor(0,0);
return 0;
}
Brendan
-
harryp, does that work? Once you move the cursor and then print a character, doesn't the cursor scroll off the screen regardless?
-
I've tried everyones suggestions, but none of them seem to do the trick. The cursor still moves onto the next line by default.
-
I gather then there is nothing that can be done to prevent the new line from occuring?