I'm working on a program with menus, but I don't know how to clear the screen before displaying the next menu.

if its just in the dos screen

#include <iostream>
#include <cstdlib>

using namespace std;

int main()
{
cout << "Hello World!" << endl;
system("cls");
cout << "End of program";
system("pause");
return 0;
}

you can put any dos command in the quotes... but make sure you include cstdlib

linux: system("clear");

thnx guys but is there any anther way to do that without <cstdlib>?

nope clearing a terminal window is hadnled by the operating system's kernal, exclusively.

actually there is a way around that... you could cout a bunch of back spaces...

cout << "\b\b\b\b\b\b";

or you could cout the ascii equivilent;)

Yea u can...backspaces need to b calculated...however thers a simple approach to the problem
jus print the required number of newline chars i.e '\n'
use the following code:
for(int i=1;i<26;i++)
cout<<"\n';

if ur program works on a loop structure then i'd suggest using the system("clear") option (Linux) or system("cls") for Windows

#include <conio.h>
......
main() {
.....
clrscr();
.....
}

Thnx Guys:D

hey i tried to clear screen using "conio.h> but it doesnt work then i tried again using
<process.h> or <windows.h> and it work good .. :D

Well done ! :cool:

Actually the <conio,h> works....atleast if u use "void main()"
N you shud add the "clrscr();" after the opening braces....(but not towards the end...as ur result will get wiped out before being 'outputted')

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.