Some general questions

Hi everyone,

I am pretty new in programming and have learned the basics of C++ in the past few weeks. Now i have a few general questions:

What is the best way to clear the screen? I'm using system("cls"), but i have hearded it's best to avoid using system. So is there another way?
And is there a way to clear a part of the screen, not everyting?

Is there a way to pause the program until the user hit enter? In this case i dont only want to avoid a system command for some abstract reason: system ("pause") cause ugly output on the screen, and i dont want that.

How do you build a library? I have downloaded the sourcecode of zlib (www.zlip.net) because i wanted to install PNGwriter and that requires zlib. However, i dont know how to 'build' the program. I read someting using nmake in command promt on the makefile.msc, but cp dont recognize nmake.
Last edited on
What is the best way to clear the screen? I'm using system("cls"), but i have hearded it's best to avoid using system. So is there another way?
And is there a way to clear a part of the screen, not everyting?


It doesn't matter. You'll eventually stop writing console apps for all but the most basic of input/output programs. So don't read too much into it. Understand the fundamentals of the language more.

Is there a way to pause the program until the user hit enter? In this case i dont only want to avoid a system command for some abstract reason: system ("pause") cause ugly output on the screen, and i dont want that.


1
2
char a
cin >> a;


How do you build a library? I have downloaded the sourcecode of zlib (www.zlip.net) because i wanted to install PNGwriter and that requires zlib. However, i dont know how to 'build' the program. I read someting using nmake in command promt on the makefile.msc, but cp dont recognize nmake.


Read the Install and ReadMe files for that libary. Each one is different. Most however require a Linux style command line so you might wanna download Cygwin or MSYS.
Thanks for the answers.

About pausing the program: i have tried your solution, but the user has to input someting before hitting enter. Otherwise there is no value read into a, and the program will just run the cin command again (i dont know how this works, but that is the result). I want a command that pauses the program, until the user hits enter, and just enter.

I have read the ReadMe files etc., but i didnt understand a lot of it :) I will try Cygwin/MSYS.
In this site you can find a big discussion about keeping the console running: http://www.cplusplus.com/forum/beginner/1988/
the solution given there should be something like this:
cin.ignore( std::numeric_limits<std::streamsize>::max(), '\n' ); but I think that you should read that discussion.
If you want to use the cin.get() method, you must add cin.sync() before it.
To clear screen you can display 100 newlines.
To insert pause to your program use cin.get(); or use ncurses library
cin.ignore(); by itself works too.
I usually use cin.ignore(80, '\n'); cause it's been drilled it into me ;p
The one problem with this is it dosen't work so well right after a statement like:
 
cin >> var;

Because there's still a newline hanging around the inputstream.
In this case you might use cin.ignore(2);

Personally I like system("cls"); best because your output starts at the top of the screen. With printing 25 or more new lines you sort of get a typewriter effect.
I really can't think of a reason you would need a lightning fast cls anyways, are you animating some ascii? lol

As for clearing only part of the screen, I don't know of any way. I suspect you'll be stuck with clearing and rewriting the data you want to persist.
Last edited on
To clear part of screen?...!!!..?
Somebody told me in this forum

if you know where character is, you can use gotoxy() and replace character with space...

I think you then you can replace spaces with '\b'
Thanks for all the help.

cin.ignore() and cin.get() both do what i want, so that problem is solved. I have read a bit of the closing console topic, interesting discussion, but to long the read it all :)

I needed the clearscreen-command because i'm creating a (really simple, text-based) game, and i just want to clean the screen a few times. so system("cls") works fine, but i have learned to avoid using system commands as much as possible. I will use it this time anyway :)
The question about clearing only a part of the screen was just out of curiosity. I'm not familiar with the gotxy() function, but i think clearing and rewriting will be easier than replacing every single character i want to clear.

Again: thanks for helping everyone
Last edited on
Topic archived. No new replies allowed.