If we can't even clear the screen without ANSI escape codes and ANSI.SYS how are we supose to make programs??
Is there another way?
If we can't even clear the screen without ANSI escape codes and ANSI.SYS how are we supose to make programs??
Is there another way?
Code:#include <stdlib.h> #include <iostream.h> int main() { cout<<"I am text"<<endl; system("CLS"); cout<<"My buddy is gone"<<endl; cin.get(); }
Add return 0 to the above.
Truth is a malleable commodity - Dick Cheney
Eh.. not the best way to do it. The FAQ has all the answers
"Queen and huntress, chaste and fair,
Now the sun is laid to sleep,
Seated in thy silver chair,
State in wonted manner keep."
>Add return 0 to the above.
Not required with C++. If the return statement is omitted from main then the return value will be 0.
-Prelude
My best code is written with the delete key.
#include<conio.h>
#include<iostream.h>
int main()
{
cout<<"Press a key to clear the screen...";
getch();
clrscr(); //requires conio.h
return 0
}
This function works on Borland C++ compilers. Try it on yours, it just might work. An alternative is to use system("CLS").
Last edited by sundeeptuteja; 06-26-2002 at 01:53 PM.
Well, Prelude, I'll defer to you every time, but if that's so, why have you made such a big deal about it in previous posts? Just asking...
Truth is a malleable commodity - Dick Cheney
Yea, I forgot to put it in, and I think you are supposed to have a return statement unless you use void main(), which you shouldn't
Thank you but theres still a problem:
consider this snippet:
cout << "Hi!\n";
getchar();
system("CLS");
cout << "Hi again!\n";
You would think it say 'Hi!',then wait for a carriage return/line-feed,then clear screen,and say 'Hi again!',but it doesn't.It waits for a carriage return/line-feed,then clears screen and prints
Hi!
Hi again!
And please tell me c++ has a way to clear the screen on its own!
It sure does. Try this:Originally posted by Powerfull Army
And please tell me c++ has a way to clear the screen on its own!:
That should do it.PHP Code:
for (int i = 0; i < 25; i++)
{
for (int j = 0; j < 80; j++)
cout << " ";
}
Truth is a malleable commodity - Dick Cheney
READ THE FAQCode:#include <windows.h> #include <conio.h> #include <iostream> using namespace std; void clrscr() { COORD coordScreen = { 0, 0 }; DWORD cCharsWritten; CONSOLE_SCREEN_BUFFER_INFO csbi; DWORD dwConSize; HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(hConsole, &csbi); dwConSize = csbi.dwSize.X * csbi.dwSize.Y; FillConsoleOutputCharacter(hConsole, TEXT(' '), dwConSize, coordScreen, &cCharsWritten); GetConsoleScreenBufferInfo(hConsole, &csbi); FillConsoleOutputAttribute(hConsole, csbi.wAttributes, dwConSize, coordScreen, &cCharsWritten); SetConsoleCursorPosition(hConsole, coordScreen); } int main(int argc, char *argv[]) { cout << "Hello"; getch(); clrscr(); cout << "Hello Again!"; return 0; }
"There are three kinds of people in the world...
Those that can count and those that can't."
thanks okie smokie and salvenis but:
salvenis,that isn't realy clearing the screen,its scrolling the screen,that'd be good for a replacement but i think c++ outa have a good,simple,complete,and authentic way to do such a simple task such as clearing the screen.
And okiesmokie thanks for the function but it still clears the screen before couting.
Do you mean it does this?
Output:
Hi!
(clear screen)
Hi Again!
because if it does that's what it's supposed to do.
No,it does this
(wait for enter press)
(clears screen)
Hi!
Hi again!
Its frustrating isn't it?
If anyone has an answer to this disgusting riddle please don't hide it
I know people make full-blown applications with c++ all the time so theres got to be a simple way to clear the screen