Clearing the console in C++

I'm using Notepad++ and NppExec to begin writing c++ code, and I was wondering how I could clear the screen. I've tried system("cls") as well as some other things that many have said worked, but when I put something like this:

do {
std::cout<<"Hello";
system("cls");
} while (true);

(Obviously not including libraries required and main) It doesn't clear anything, and the hello message just gets repeated continuously. Is it impossible to clear the screen this way, or is it a problem with Notepad++? Any help would be greatly appreciated. P.S. I've also tried manual clearing functions as well as a for-loop which creates 100 new lines. All of them do nothing.
All of them do nothing.

Seems unlikely.
Post a complete program that demonstrates the problem.
Have a look at this demo.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <thread>

void sleep_millis(unsigned int ms)
{
  std::this_thread::sleep_for(std::chrono::milliseconds(ms));
}

int main()
{
    std::cout << "Hello, this should stay on the screen for 2000ms\n";
    std::cout << "Hello, this should stay on the screen for 2000ms\n";
    std::cout << "Hello, this should stay on the screen for 2000ms\n";
    std::cout << "Hello, this should stay on the screen for 2000ms\n";

    sleep_millis(2000);
    system("cls");
    std::cout << "Now the screen has been cleared and a new msg appears.";
}


If NppExec doesn't show a normal Windows cmd console, then there's no guarantee that a system command like cls will do anything useful.

Looks like NppExec is its own custom console.

https://sourceforge.net/p/npp-plugins/discussion/672146/thread/9b869427/
While something is working inside NppExec - in your case it's a weblogic server - all the typed commands come into that working thing (a weblogic server in your case). So when you type "cls" while the server is running, this "cls" command is processed by the server itself. And, even if the server itself clears its console by the "cls" command, NppExec can not show you this since NppExec's just "monitors" the server's console's output and shows it in NppExec's Console.


NppExec is not a console emulator. NppExec redirects the running process'es output to its Console window, and can redirect the Console window's input to the running process (with some limitations). The NppExec's Console is not a "real" console window (actually, it uses RichEdit control for text input/output), it does not provide a console screen buffer. Thus, a console application which requires a "real" console screen buffer must be run in its own console window (using NPP_RUN command).
Last edited on
cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n ......" will clear the screen, of sorts.
it isnt the cleanest thing ever, but looking at the above post, it may be all you can do.
Last edited on
Topic archived. No new replies allowed.