Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Apr 17th, 2006, 12:04 AM   #1
Nickyj1211
Newbie
 
Join Date: Apr 2006
Posts: 15
Rep Power: 0 Nickyj1211 is on a distinguished road
Quick question HELP!

Just got my crap to start working correctly. Just wanted to know one thing. What is the code for reseting the console screen? As in, in a simple counting and output loop, the numbers wont appear like this:

1
2
3
4
5

But will stay in place, and appear in the same spot. Basically, how do you make it so when you output anything, it restarts at the top, and you cannot read what has already been outputted?

Last edited by Nickyj1211; Apr 17th, 2006 at 12:27 AM.
Nickyj1211 is offline   Reply With Quote
Old Apr 17th, 2006, 4:27 AM   #2
Jimbo
Battle Programmer
 
Jimbo's Avatar
 
Join Date: Feb 2006
Location: Bellevue, WA, USA
Posts: 770
Rep Power: 3 Jimbo is on a distinguished road
for(int i = 0; i < 100; i++)
   std::cout << "\n";
std::cout << std::endl;
Jimbo is offline   Reply With Quote
Old Apr 17th, 2006, 6:17 AM   #3
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Quote:
Originally Posted by Nickyj1211
Basically, how do you make it so when you output anything, it restarts at the top, and you cannot read what has already been outputted?
Till ten this works great, but see the text above underlined.
#include <iostream>

using namespace std;

int main()
{
	for(int i = 0; i < 10; i++)
		cout << i << '\b';
	return 0;
}
Please read the "How to post a question" while you're at it.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Old Apr 17th, 2006, 8:13 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
I would enjoin you to think for forty or fifty seconds until you realize that an output device is a very implementation-specific thing. If you don't believe me, ask a blind person. A general-purpose, 'portable' language attempts to ignore the reality that an output device of some sort will ultimately be required. They leave it to the implementors. Don't go looking in the standard library for such things. You can find your ass with both hands much easier.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 17th, 2006, 11:24 AM   #5
Nickyj1211
Newbie
 
Join Date: Apr 2006
Posts: 15
Rep Power: 0 Nickyj1211 is on a distinguished road
Quote:
Originally Posted by nnxion
Till ten this works great, but see the text above underlined.
#include <iostream>

using namespace std;

int main()
{
	for(int i = 0; i < 10; i++)
		cout << i << '\b';
	return 0;
}
Please read the "How to post a question" while you're at it.
Nim u dont need the simple code to for the loop, i need how to clear out the screen. One of my programming buddies from last year was shown how to do it with some type of "clear screen" code. I remember it being really simple, but i dont know how to use it. Whatever it is, all you would have to do is use the code within the function to erase the previous output. But i dont know what the code is.
Nickyj1211 is offline   Reply With Quote
Old Apr 17th, 2006, 11:33 AM   #6
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
It IS very simple. It also depends entirely upon your implementation. Read your responses. Rub two brain-cells together. I'll bet you a hunnert bucks you can't clear the screen on a teletype machine without having to pay for a roll of paper. If you want to talk about kiddie machines like one finds on zillions of desktops, say so.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Apr 17th, 2006, 11:35 AM   #7
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,473
Rep Power: 8 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
I'm going to assume you are using windows. Below is non-portable code to clear the screen.

#include <conio.h>
...
clrscr();
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Apr 17th, 2006, 11:42 AM   #8
Nickyj1211
Newbie
 
Join Date: Apr 2006
Posts: 15
Rep Power: 0 Nickyj1211 is on a distinguished road
Quote:
Originally Posted by Infinite Recursion
I'm going to assume you are using windows. Below is non-portable code to clear the screen.

#include <conio.h>
...
clrscr();
THANK YOU! thats what i have been looking for.. thats what i meant. Thanks for your help
Nickyj1211 is offline   Reply With Quote
Old Apr 17th, 2006, 11:52 AM   #9
Nickyj1211
Newbie
 
Join Date: Apr 2006
Posts: 15
Rep Power: 0 Nickyj1211 is on a distinguished road
Quote:
Originally Posted by DaWei
It IS very simple. It also depends entirely upon your implementation. Read your responses. Rub two brain-cells together. I'll bet you a hunnert bucks you can't clear the screen on a teletype machine without having to pay for a roll of paper. If you want to talk about kiddie machines like one finds on zillions of desktops, say so.
I dont understand what you mean, the clrscr() code works. Am i missing something? It doesnt scroll the window or anything... what am i missing?
Nickyj1211 is offline   Reply With Quote
Old Apr 17th, 2006, 12:00 PM   #10
nnxion
Programming Guru
 
nnxion's Avatar
 
Join Date: Jun 2005
Location: elemental plane
Posts: 1,429
Rep Power: 5 nnxion is on a distinguished road
Nicky you _really_ need to listen to DaWei. conio.h is not portable, we could give you code for *nix with the curses library, or some code for you Playstation Portable, but it's not going to be portable. Comprende?
You might also like to search the forums, this question has been asked multiple times and some semi portable solutions have been provided.
__________________
"Employ your time in improving yourself by other men's writings, so that you shall gain easily what others have labored hard for."
-- Socrates
nnxion is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 2:23 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC