Y este es otro ejemplo usando gotoxy y scroll:
#include <iostream>
#include <windows.h>
#include <time.h>
using namespace std;
void wait (int seconds); // timer
void clrscr (); // clear the screen
void gotoxy(int x, int y); // move to specific position in console
void scroll (char *s, int x); // scroll a line of text
int main()
{
// call our scroll function with the string and the y coordinate
scroll ("Hola esto es una cadena de texto.\n",30);
scroll("Y esto es otra cadena que tambien se mueve", 35);
return 0;
}
// wait a period of time
void wait ( double seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
// clear the screen
void clrscr ()
{
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); // gets the window handle
COORD coord = {0, 0}; // sets coordinates to 0,0
DWORD count;
CONSOLE_SCREEN_BUFFER_INFO csbi;
GetConsoleScreenBufferInfo(hStdOut, &csbi); // gets the buffer info (screen)
// fill all characters as ' ' (empty the screen)
FillConsoleOutputCharacter(hStdOut, ' ', csbi.dwSize.X * csbi.dwSize.Y, coord, &count);
// resets the cursor position
SetConsoleCursorPosition(hStdOut, coord);
}
// move to a specific point in the console window
void gotoxy (int x, int y)
{
COORD coord; // coordinates
coord.X = x; coord.Y = y; // X and Y coordinates
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord); // moves to the coordinates
}
void scroll (char *s, int x)
{
// loops and leaves some space at the top/bottom border
for (int i = 19; i >= 5; i--)
{
gotoxy (x,i); // move up one line
cout << s; // output the string
wait(0.5); // wait one second
clrscr (); // clear the screen
}
}