Jake Korman
Jake Korman

Reputation: 55

Is it possible to print to a clear integrated terminal in VSCode

I want the output from my program to be printed on an empty terminal. ie, instead of,

PS C:\Stuff\More Stuff>  & 'c:\Users\user\.vscode\extensions\ms-vscode.cpptools-1.4.1\debugAdapters\bin\WindowsDebugLauncher.exe' '--stdin=Microsoft-MIEngine-In-w1d2d2zg.skd' '--stdout=Microsoft-MIEngine-Out-2q3w4dx4.xne' '--stderr=Microsoft-MIEngine-Error-sr0qr1un.pod' '--pid=Microsoft-MIEngine-Pid-zddzumbv.aaf' '--dbgExe=C:\Program Files\CodeBlocks\TDM-GCC-64\bin\gdb.exe' '--interpreter=mi'
Hello from my program

I want,

Hello from my program

Here is my launch.json if it's of any help,

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "g++.exe - Build and debug active file",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${fileDirname}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "gdb",
            "miDebuggerPath": "C:\\Program Files\\CodeBlocks\\TDM-GCC-64\\bin\\gdb.exe",
            "setupCommands": [
                {
                    "description": "Enable pretty-printing for gdb",
                    "text": "-enable-pretty-printing",
                    "ignoreFailures": true
                }
            ],
            "preLaunchTask": "C/C++: g++.exe build active file"
        }
}

So, is there a way to output the program into an empty terminal?

Edit: I found a similar question here, but the solution posted doesn't work for me. It says, "Property console is not allowed". I am using the f5 debugger to run my C++ programs. I found some other similar questions, but they don't have an answer.

Upvotes: 0

Views: 454

Answers (1)

Jake Korman
Jake Korman

Reputation: 55

For now, the best working solution I could find is running the following command at the start of the program.

int main()
{
    cout << "\033[2J\033[1;1H";

    /*rest of the code here*/
}

This clears the terminal before execution of the actual program. This will also clear any outputs from previous runs. I'd prefer to have my previous outputs.

Upvotes: 1

Related Questions