Thread: Preventing Newline

  1. #1
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367

    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.
    Be a leader and not a follower.

  2. #2
    Registered User
    Join Date
    Sep 2002
    Posts
    9
    maybe if you set the width to 80 and right aligned

    EDIT: ie cout.width=80;

  3. #3
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    Thanks, it still made no difference. The cursor still went onto the next line.
    Be a leader and not a follower.

  4. #4
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    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

  5. #5
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    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.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  6. #6
    Registered User harryP's Avatar
    Join Date
    Sep 2002
    Posts
    124
    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
    Draco dormiens nunquam titallandus.
    Console Graphics Library: http://www.geocities.com/steve_alberto/cgl.html

  7. #7
    Banal internet user
    Join Date
    Aug 2002
    Posts
    1,380
    harryp, does that work? Once you move the cursor and then print a character, doesn't the cursor scroll off the screen regardless?

  8. #8
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    I've tried everyones suggestions, but none of them seem to do the trick. The cursor still moves onto the next line by default.
    Be a leader and not a follower.

  9. #9
    Registered User subdene's Avatar
    Join Date
    Jan 2002
    Posts
    367
    I gather then there is nothing that can be done to prevent the new line from occuring?
    Be a leader and not a follower.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newline characters
    By xRandyx in forum C Programming
    Replies: 3
    Last Post: 11-15-2005, 11:01 AM
  2. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 10:46 AM
  3. reading newline
    By winsonlee in forum C Programming
    Replies: 4
    Last Post: 03-19-2004, 12:41 PM
  4. fgets and a bothersome newline char
    By ivandn in forum Linux Programming
    Replies: 1
    Last Post: 11-14-2001, 01:41 PM
  5. newline / memset
    By frenchfry164 in forum A Brief History of Cprogramming.com
    Replies: 4
    Last Post: 10-31-2001, 01:21 AM