hi

can anyone tell me what do we mean by:

system( "PAUSE" );

and

system( "CLS" );


in C++

thanks

Dani AI

Generated

Short explanation and safer options.

The two calls in the original post ask the C runtime to hand a string to the host shell/command processor. One prints a short prompt and blocks until a key is pressed; the other clears the terminal. Because the command string is executed by the OS shell, behavior is platform-dependent, may behave differently inside IDE consoles or when I/O is redirected, adds overhead and can be a security risk if the command string contains untrusted data.

Safer alternatives for pausing:

  • Use standard input to wait for the user (this waits for Enter).
  • If a single keypress is required, use a small platform-specific read (Windows has a simple API; POSIX needs a short termios tweak).

Example (wait-for-Enter and single-key on Windows/POSIX):

#include <iostream>
#include <string>

void wait_for_enter() {
    std::string s;
    std::getline(std::cin, s);
}

#ifdef _WIN32
#include <conio.h>
void wait_for_key() { _getch(); }
#else
#include <termios.h>
#include <unistd.h>
int wait_for_key() {
    termios oldt, newt;
    tcgetattr(STDIN_FILENO, &oldt);
    newt = oldt; newt.c_lflag &= ~(ICANON | ECHO);
    tcsetattr(STDIN_FILENO, TCSANOW, &newt);
    int c = getchar();
    tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
    return c;
}
#endif

Safer ways to "clear" the screen:

  • Emit ANSI sequences when the terminal supports them.
  • Use the native console API on Windows for a clean, flicker-free clear.

ANSI example:

#include <iostream>
void clear_screen_ansi() { std::cout << "\x1b[2J\x1b[H"; }

Final notes: prefer standard-library I/O or native console APIs over calling the shell. As noted, shell calls are OS-dependent; pointed toward input-based waits; and highlighted references and portability concerns. Avoid using shell invocation in production code and never build shell commands from untrusted input.

Recommended Answers

All 5 Replies

hi

can anyone tell me what do we mean by:

system( "PAUSE" );

and

system( "CLS" );


in C++

thanks

system("PAUSE"); the program waits for you to enter a key
system("CLS"); clears the console or command line terminal

both of makes your program not portable since is operating system
depended

See this about system("pause"); system("cls"); is conceptually similar.

thank u guys!!!

use

getchar(); 
or
cin.get();

instead of system("pause");

Well, the System("pause"); actually a function to the main windows shell, which calls pause.exe, and thereby pauses your program. And just to let you know, the System("PAUSE") method is a bad way of pause your applications...

A good alternative is at:


As for System("CLS") function, it clcears your console applications screen. Basically erasing any user or application genereated output on the screen.

Please let me know if this helps you.

Thank,
Lance Wassing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.