Yesterday I wanted to clear the screen in my Console app, so I called the function clrscr(); which used to be a part of the conio.h file, but it wasn't there!! Why is that??
Printable View
Yesterday I wanted to clear the screen in my Console app, so I called the function clrscr(); which used to be a part of the conio.h file, but it wasn't there!! Why is that??
clrscr() is a non standard function. It's only borland's Implementation.
so You have to include stdlib.h
and use
system("cls");
I'm glad you brought this up...I was working on a console app and had the same problem.
Later,
Paul
Sorry but this function dosen't work for me, can u specify some example code? I know this is really simple, but when i use
system("cls");
it wont do anything!
i included stdlib.h and im using VC++ 6.0 SP4
Thanks!
Check the definition in the MSDN, make sure you're using it correctly. It should work fine for console apps.
i included the stdlib.h and all, just dint put it in the code.Code:int main()
{
cout << "HELLO WORLD" << endl;
system("cls");
return 0;
}
is that right?
In a VC++ console app, paste the following code in:
<iostream> is the standard header, as opposed to <iostream.h> which is the Microsoft version. The standard library functions, structs and classes are in the std namespace so cout and endl are qualified with the scope resolution operator, ::. This works just the same:Code:#include <iostream>
#include <stdlib.h>
int main()
{
std::cout << "Hello World" << std::endl;
system("cls");
return 0;
}
but by using the standard namespace you will be declaring all your variables in that namespace, which kind of defeats the point of namespaces and might make your code awkward to reuse if you want it in a different namespace.Code:#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
cout << "Hello World" << endl;
system("cls");
return 0;
}
To be honest it doesn't matter much for this but I just felt like doing it properly :)
Both examples compiled and ran fine for me. They end up with a blank screen.
Sorry but it does not. Thank you for the reply, but i think this is a problem here. The computer i tried this on is running fortress security, and maybe they locked us out of certain things.
I will try this at home and let you know what happens.
Thanks alot for all the posts,
greatly appriciated
:confused:
:(
:mad:
[QUOTE]Originally posted by HarryW
[\QUOTE]Code:#include <iostream>
#include <stdlib.h>
using namespace std;
int main()
{
cout << "Hello World" << endl;
system("cls");
return 0;
}
cstdlib is the standard header for stdlib.h.
so the code would be:
:pCode:#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
cout << "Hello World" << endl;
system("cls");
return 0;
}
Yes I'm well aware of that Dennis, but I wasn't sure if the system() function was M$-specific, so I used their version.
So :p back at ya
cstdlib merely #includes stdlib.h inside the std namespace :)
Did you remember to include the header file?Quote:
Originally posted by invitro
Sorry but it does not.
I am using the same system function to clear my screen in linux ;)Quote:
Originally posted by HarryW
Yes I'm well aware of that Dennis, but I wasn't sure if the system() function was M$-specific, so I used their version.
So :p back at ya
system("clear");