does any1 have any idea about how to,when i press a button,print out 1 line of text written by me and when i press it again another replaces the old?
i already got the saving working so u dont have to worry about that

Recommended Answers

All 8 Replies

If tried do describe your problem more clearly, I might be able to answer your question.
What I understand is "I want one line of text replaced by a second line when I press a key"

This could be done like this:

#include <windows.h>
#include <iostream>

using namespace std;

void clear_screen ( void )
{
    DWORD n;                         /* Number of characters written */
    DWORD size;                      /* number of visible characters */
    COORD coord = {0};               /* Top left screen position */
    CONSOLE_SCREEN_BUFFER_INFO csbi;

    /* Get a handle to the console */
    HANDLE h = GetStdHandle ( STD_OUTPUT_HANDLE );

    GetConsoleScreenBufferInfo ( h, &csbi );

    /* Find the number of characters to overwrite */
    size = csbi.dwSize.X * csbi.dwSize.Y;

    /* Overwrite the screen buffer with whitespace */
    FillConsoleOutputCharacter ( h, TEXT ( ' ' ), size, coord, &n );
    GetConsoleScreenBufferInfo ( h, &csbi );
    FillConsoleOutputAttribute ( h, csbi.wAttributes, size, coord, &n );

    /* Reset the cursor to the top left position */
    SetConsoleCursorPosition ( h, coord );
}

int main()
{
    std::cout << "line one. Press enter";
    std::cin.get();
    clear_screen();
    std::cout << "\rsecond line";
    std::cin.get();
    return 0;
}

(code from here)

Yeah. Other than cin.get(), you can use getchar() or system("pause"). Other than clear_screen you can use system("CLS").

Yeah. Other than cin.get(), you can use getchar() or system("pause"). Other than clear_screen you can use system("CLS").

That would be a silly thing to do. The system("something"); command is not-portable, this means that it will only work on 'some' OS.
Besides, if you use the system() command and someone decides to change the "CLS" executable to "format c: /q" , your program will format the user's HD.

Aint that funny? So next time you would like to comment on my code, please do research first ;)

sry,i forgot to tell u its a dialog box and the text appears in a edit control
:|

nvm,i got it working,except im trying to get it so that the getline function skips to the next line when i press the button again

That would be a silly thing to do. The system("something"); command is not-portable, this means that it will only work on 'some' OS.
Besides, if you use the system() command and someone decides to change the "CLS" executable to "format c: /q" , your program will format the user's HD.

Aint that funny? So next time you would like to comment on my code, please do research first ;)

There is no need to be mean niek_e. Just trying to help. Anyway, I did learn something new. Thanks. :sad:

There is no need to be mean niek_e.

I wasn't trying to be mean, I was trying to be informative. I put a smily in the post to indicate that I wasn't trying to be mean :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.