#include <iostream> #include <windows.h> #include <time.h> using namespace std; 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 ("MyString", 35); return 0; } // 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 Sleep(1000); // wait one second clrscr (); // clear the screen } }