954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Clearing the screen

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

Lost Chyld
Newbie Poster
6 posts since Mar 2004
Reputation Points: 12
Solved Threads: 0
 

if its just in the dos screen

#include
#include

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

Bleek
Light Poster
28 posts since Mar 2004
Reputation Points: 45
Solved Threads: 0
 

linux: system("clear");

infamous
Junior Poster in Training
77 posts since Mar 2004
Reputation Points: 47
Solved Threads: 2
 

Thanx guys.

Lost Chyld
Newbie Poster
6 posts since Mar 2004
Reputation Points: 12
Solved Threads: 0
 

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

meabed
Junior Poster
Team Colleague
139 posts since May 2004
Reputation Points: 55
Solved Threads: 3
 

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

BountyX
Posting Whiz in Training
230 posts since Mar 2004
Reputation Points: 28
Solved Threads: 9
 

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;)

Bleek
Light Poster
28 posts since Mar 2004
Reputation Points: 45
Solved Threads: 0
 

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

Snyper
Newbie Poster
2 posts since May 2004
Reputation Points: 11
Solved Threads: 0
 

#include
......
main() {
.....
clrscr();
.....
}

skywing
Newbie Poster
5 posts since May 2004
Reputation Points: 11
Solved Threads: 0
 

Thnx Guys:D

meabed
Junior Poster
Team Colleague
139 posts since May 2004
Reputation Points: 55
Solved Threads: 3
 

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

meabed
Junior Poster
Team Colleague
139 posts since May 2004
Reputation Points: 55
Solved Threads: 3
 

Well done ! :cool:

skywing
Newbie Poster
5 posts since May 2004
Reputation Points: 11
Solved Threads: 0
 

Actually the 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')

wildrider30
Newbie Poster
4 posts since Apr 2004
Reputation Points: 11
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You