confused on clearing the screen

so i read an article here by the user duoas, and was wondering if someone could explain it... i saw that he suggested clearing the screen with something like this: for(int i = 0; i < 100; i++) std::cout<< std::endl; . i cant quite remember off the top of my head. while he did say it was a bad way, i was curious as to how it worked? because what if it was a big monitor with more than 100 lines, or you werent at the beginning of the screen, say at line 50, so it doesnt reset the cursor, instead it blanks it, but the cursor is still at line 50 (assuming the terminal had 100 lines)
It just outputs 100 empty lines.
If your terminal has more than 100 lines, some of the previous output will still be visible. It also makes terminal history look ugly, hence it is a bad way.
@Little Bobby Tables

That's why it's a bad method. The best way to clear the screen (of a terminal) is through the operating system's native API. However, if you want to make a program that's easy to set up, and can also be cross-compiled, and a clean clear-screen isn't required, only preferred, then displaying a bunch of newline characters becomes appealing.
You'll also notice that the article does the opposite of recommend it.
@MiiNiPaa: thank you thats what i thought
@IWish: yeah i know how. i actually already have a "cross platform" clear function (which actually just compiles certain parts of the code based on macros)
@duoas: i understand. you just write a lot of code that goes over my head, so i just wanted to make sure i wasnt missing anything in the article, because it didnt seem like a guaranteed clear to me
You're right. The only "guaranteed" clear is the system/terminal-specific one. On PCs all terminals look the same, so you can (except rarely) guarantee a clear. On *nixen there is a significantly larger range of hardware in play, so you cannot guarantee anything... Most Linux distros are designed to work with sane terminals, though, so you can safely assume it will work.
Topic archived. No new replies allowed.