vscode how to output in seperate consile
#include <stdio.h>
int main() {
printf("This will be printed in the main console.\n");
// Create a new console window for output
system("cmd /c start cmd.exe /k \"echo This will be printed in a separate console window.\"");
return 0;
}
Explanation:
#include <stdio.h>
: Includes the standard input/output header file for functions likeprintf
.int main() { ... }
: Defines the main function where the program execution begins.printf("This will be printed in the main console.\n");
: Prints a message to the main console.system("cmd /c start cmd.exe /k \"echo This will be printed in a separate console window.\"");
: Executes a system command to start a new command prompt (cmd.exe
) in a separate window./c
carries out the command and then terminates,/k
keeps the command prompt window open after executing the command. Inside this command prompt,echo
is used to print a message, and this message will be shown in the separate console window.return 0;
: Indicates successful execution and termination of the program.
This code will display one message in the main console and open a new console window displaying another message using the system
function to execute a command to open a separate console.