I cant use clear screen function in my program when using code blocks

+2 Sudershan Ravi · December 29, 2014
i am beginner in c++ programming and when i was just practicing i used the function(i think its a function) clrscr(); and it showed error as "its not declared in scope". What should I do to avoid this error and clear my screen.
Thank you

Post a Reply

Replies

Oldest  Newest  Rating
0 Bernard Pyc0d333 Parah · December 29, 2014
if you are using windows the command is system("cls");
i did this example on linux since that is what i use.



#include<iostream>
#include<cstdlib>  //include this header in order to be able to use the system() fucntion
using namespace std;

int main()

{
    int a;
    cout<<"enter a "<<endl;
    system("clear");  // use "cls" in the parenthesis for windows.
    cin>>a;

    return 0;
}

0 Brian Mwangi · January 2, 2015
Use the header :

#include <stdlib.h>

Then where you wanna clear the screen, use

system( "cls" );

Tell me if it works!
0 Laura Lee · January 3, 2015
As stated by Krootashus, C++ does not have any formal portable method of clearing the screen.
It's OS dependant. On Windows, you'd have to use the WIn32 API to do it, or simply make a system call. I'd avoid system calls because of the heavy resource usage underneath. If you are wanting to use the API,
look into these two functions.

http://msdn.microsoft.com/en-us/library/windows/desktop/ms683171(v=vs.85).aspx

http://msdn.microsoft.com/en-us/library/windows/desktop/ms682663(v=vs.85).aspx
  • 1

C++

106,932 followers
About

Used in many types of software including music players, video games, and many large scale applications.

Links
Moderators
Bucky Roberts Administrator