Substitute for SŸSTEM("cls")

When I started programming in c++ I was told for the programm to look good I should use SYSTEM("cls"). So my question is, what's the replacement to this command. Thanks in advance.
cout << string(50,'\n') will do the trick.
OK, thanks for the answer. But isn´t there a more pretty way, like the user can´t role up and see what is already done.
Last edited on
You can use some library like PDCurses.
Ask yourself: do you really need to erase everything on screen?
If I had run some program and lost diff result I use in my current work, I'll probably remember to never use programs written by this programmer.
EDIT: And "cls: Command not found" which will pop up every time when I launch your program isn't making it look good :)

Also: http://www.cplusplus.com/forum/articles/11153/
Last edited on
I'll explain. I'm making a program wich in its start has a login, register and exit menu. Imagine you need to register, you don't want that after that it shows everything you have done. So you would want to clear the screen. And I for now all my projects are directed to windows only so my problem isn't about OS dependency, it's about the slowness and the security gap. I think there should be a way to do this without using the system() commands. Altough I'm not worried about OS dependecy it's very likely to become a problem in the future if try to expand my horizonts. And if I use PDCurses what does it do and how does it do it?
Then why are you using console? PDCurses looks like that:
http://www.projectpluto.com/win32a.htm

Alternatively you can learn WinAPI and make complete windows program.

Quiz question: How to make symbols which user enters to show up as asterisks? (For example you are asking user to enter password.)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include<iostream>
#include<string>
#include<conio.h>
#include<stdlib.h>

(...)

char ch;
ch = _getch();
while (ch != 13){
string stuff;
stuff.push_back(ch);
cout << '*';
ch = _getch();
}

(...)


Ok, but you forgot to check for other special symbols (like TAB, escape, and others) and possibility to use backspace to delete last char will be neat, but this is good too.
So, did you decide on something? Do you really need it on console?
I said console because I'm still learning to programm and I still barely know c++. So for now I'm sticking to the console. When I have learned enough and I can make a good console aplication will start using libraries like PDCurses or even more seriusly OpenGL or DirectX. I started programming with the objective of making a game so my goal will be OpenGL.
http://www.cplusplus.com/articles/4z18T05o/
cut n paste what you need

you should try to avoid writing your program so that it messes with the user's console, unless it is an intrinsic characteristic of the application itself

hope this helps
It realy helped. I'm going with the conio.h way cause I already use it in my programs so I don't have to include more headers. Thanks a thousand!!!
How's this :
1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream.h>

void pause() {
std::cin.sync();
std::cin.get();
}

int main() {
std::cout << "Hello." << std::endl;
pause();
return 0;
}
Topic archived. No new replies allowed.