0

I'm new to c++. I am having a trouble with creating a clreol(); (clear end of line) function in C++ language. And also I am using Code::Blocks.The header file you're trying to use is very old and outdated. I'm trying to do like: `

void LINES::CLEARDOWN(void)
{
 for (int i = 1; i <= 25; i++)
 {
  sleep(20);
  gotoxy(1, i);
  clreol();
 }
}

Can anyone please tell me the alternate way to use clreol()

krishna veer
  • 474
  • 1
  • 4
  • 16
  • You need to include the header file with the declaration of the function ```clreol``` you want to use, so probably ```#include "conio.h"```, but see discussion here https://stackoverflow.com/questions/21329485/why-must-we-refrain-from-using-conio-h-is-it-obsolete and in links therein. – ctenar May 14 '20 at 10:06
  • Thanks for response but I'm already using `#include "conio.h` and I'm also using GNU GCC Compiler. Can you please elaborate what you want to say? – krishna veer May 14 '20 at 10:16

1 Answers1

1

You can replicate the functionality of clreol() using ANSI escape sequences. Note that this will not work on windows.

The escape sequence to clear a line from the right of the cursor is Esc[K, to write this to the terminal in C++ we can do this:

std::cout << "\033[K";

(\033 is ESC)

To move the cursor back one we can do

std::cout << "\033[1D";

(Where 1 is the amount we are moving by and D specifies backwards aka left)

And so on and so forth. Wikipedia has a description of ANSI escape codes and how they are "constructed". If you want to do heavy manipulation of terminal graphics (i.e are writing a terminal GUI) then you should consider ncurses.

Object object
  • 1,939
  • 10
  • 19