Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Visual C++

Posted on 1998-05-27
15
Medium Priority
?
251 Views
Last Modified: 2013-12-14
What is the command for clearing the screen in Microsoft's visual C++ and what library does it use?  (I know how to add new lines - I want my cursor to end up at the top of the cleared screen)  By the way - Borland's clearscreen command does not work for me with Visual - ??
0
Comment
Question by:Reid
  • 6
  • 3
  • 2
  • +2
15 Comments
 
LVL 23

Expert Comment

by:chensu
ID: 1164837
#include <stdlib.h>

system("cls");
0
 

Expert Comment

by:zaphord
ID: 1164838
zaphord,

I am sure Reid is talking about a Console application, not a Windows GUI application.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1164839
chensu,

In that case your sollution is correct.
And I did preface my sollution with:
"If the problem is in a client window"
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Expert Comment

by:zaphord
ID: 1164840
Although system("cls") will work it does have some drawbacks.

"The system function passes command to the command interpreter, which executes the string as an operating-system command.  You must explicitly flush (using fflush or _flushall) or close any stream before calling system"

A native way of clearing the console in a Win32 application is presented in a KnowledgeBase article Q99261 (accessible from the online help).

A DOS application (MSVC 1.5x only) can use the clrscr() function.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164841
I am working on a console application - I am obviously still new at this...

chensu's answer compiled, etc, but didn't work.  I tried adding fflush and got an
"undeclared identifier" error - do I need to add another library for it?

zaphord's answer is way beyond me...
0
 

Author Comment

by:Reid
ID: 1164842
I've tried _flushall and fflush(stdin) with system("cls"), it still doesn't work.
0
 

Author Comment

by:Reid
ID: 1164843
This comment did not seem to be added -

I've flushed the buffers using fflush and _flushall - system("cls") still does not work.
0
 

Author Comment

by:Reid
ID: 1164844
If it's a real console application (using the console API under NT) then you can use the WriteConsole() function to write 80x25 characters (or whatever size your console is) to the screen. Otherwise, use printf() or puts() in a loop to clear the screen.
0
 
LVL 1

Expert Comment

by:bsimser
ID: 1164845
If I use printf or puts, my cursor still ends up at the bottom of the screen.  Can you clarify how to use the WriteConsole function?  Will my cursor end up at 1X1?
0
 

Author Comment

by:Reid
ID: 1164846
Ok, here's the deal - chensu's answer was exactly what I was looking for - except that I can't get it to work.  I am very new at this - consider my knowledge base to be minimal.  (I couldn't figure out how to find the material referenced in alexo's note).  I flush everything using _flushall(); but system("cls") doesn't do anything.  I have looked at WriteConsole, but can't figure out how to use it so my cursor is at the top.  

Thanks a lot...
0
 

Author Comment

by:Reid
ID: 1164847
This should work for you:

#include <windows.h>
#include <stdio.h>
#include <conio.h>

HANDLE hConsole;
COORD pos;

void cls()
{
    DWORD chwrote;

    hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    FillConsoleOutputCharacter(hConsole, ' ',
            80*25, pos, &chwrote);
    SetConsoleCursorPosition(hConsole, pos);
}

void main(void)
{
    pos.X = 0;
    pos.Y = 0;

    AllocConsole();
    printf("This is where your app starts...");
    getch();
    cls();
    printf("This is 0, 0");
}

0
 
LVL 1

Accepted Solution

by:
bsimser earned 400 total points
ID: 1164848
I used system("cls") method before and it worked.

The KB article alexo mentioned is at http://support.microsoft.com/support/kb/articles/q99/2/61.asp.
0
 
LVL 23

Expert Comment

by:chensu
ID: 1164849
It works!  Thanks!  Now I need to go and figure out what you did....
0
 

Author Comment

by:Reid
ID: 1164850
The accepted answer assumes the console is 80x25 charactes, which is wrong.
A Win95 console can also be 80x43 or 80x50.  An NT console can be almost any size.
0
 
LVL 11

Expert Comment

by:alexo
ID: 1164851
Well, the console I get is 80 x 25 characters..... so it works well for me.  I think that the reason system("cls") doesn't work is that this is a university owned Visual C++, and they've made some alterations so that we can not customize it to our own needs.  Now that I understand what was done, I can change the console size easily if I need to.  Thanks everyone!

Reid
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Jaspersoft Studio is a plugin for Eclipse that lets you create reports from a datasource.  In this article, we'll go over creating a report from a default template and setting up a datasource that connects to your database.
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question