PDA

View Full Version : clrscr()


scap
09-06-01, 06:29 PM
This command does seem to work in visual studio from microsoft so because i have to use this at school i was hoping that there would be a way to write a ____.h file that i could include and then it would work. any ideas. snything would be appericated
scap

P.S. sorry if i got some of the lingo wrong i am still very new to this...

engjohn
09-06-01, 09:58 PM
clrscrn() is not a function in Visual C++.
you can use the system() function to pass commands to the OS.


Routine* ****************
system
Required Header
<process.h> or <stdlib.h>
Compatibility
ANSI, Win 95, Win NT

just include either process.h or stdlib.h in your proggie.

call it like this...
system("cls"); //to clear the screen

EXAMPLE: cut and paste to your C++ editor...


//example.cpp
//shows how to include "process.h"
//and call the system() function

#include <process.h>
#include <iostream.h>

int main()
{
int answer;
cout << "this is to place some text on the screen...\n\n";
cout << "Would you like to clear the screen? \n(1 for yes, 2 for no)->";
cin >> answer;//gets the answer from user

if (answer == 1)
{
system("cls"); //this clears the screen
system("pause");// pauses to show that it cleared the screen
}

else
{
system("pause");// pauses to show that it did NOT clear the screen
}


return 0;

}

engjohn
09-06-01, 10:07 PM
here is a zipped copy of my source and the compiled exe

scap
09-06-01, 10:44 PM
yea i figured that out its just isn't there a way to make a file that you can include that would have something along the lines of clrsrc()= system("cls"); so that i could use clrsrc() instead. This may sound dumb but what this would do is allow me to use clrscr which is what we use at school making my prog more interchangable. if this is bad practice then tell me cause as i said i am very new to this.

engjohn
09-07-01, 03:09 AM
Here is a header file for you.

Put it with the rest of the header files on your system.

then you can call the function clrsrc() anywhere in your code...

A header file is really not needed in this case. A simple function definition in your project will accomplish the same thing. But here is the header file. You will notice that it is very simple.

If you would like to know how to put the function definition in your code let me know and I will show you.

scap
09-07-01, 09:18 AM
Thanks, i think this will be all i need.

engjohn
09-10-01, 02:35 AM
Oh yea, I forgot to mention in my other post. You of course need to "include" this header file in your proggie

#include <clr.h>

You probably already knew this, but I forgot to mention it... :)

Hope everything is going fine.

scap
09-12-01, 12:40 AM
it is going great now thanks

scap
09-12-01, 10:33 PM
when tring to use this it gives me the error ---------------------------
Microsoft Visual C++
---------------------------
Cannot compile the file 'C:\Program Files\Microsoft Visual Studio\VC98\Include\clr.h'; no compile tool is associated with the file extension.
---------------------------
OK
---------------------------

engjohn
09-13-01, 11:43 PM
It works just fine for me...

Show me your source code and I will see if I can find out what is wrong...

Or you can just add the function definition to your proggie...