首页 > 解决方案 > 在 VS Code 外部终端中输入后结束的 C 程序

问题描述

我在执行器映射中进行了此更改以在外部终端中运行程序:“code-runner.executorMap”:{“cpp”:“g++ $fullFileName -o $fileNameWithoutExt.exe && start $fileNameWithoutExt.exe”}

该程序确实开始在外部终端中运行,但在输入后结束。这是简单的C代码:

#include<stdio.h>
int main()
{
    int x,y,l,a,b;
    printf("Enter the bottom left co-ordinates of the square: ");
    scanf(" %d %d", &x, &y);
    printf("Enter the length of the square: ");
    scanf(" %d", &l);
    printf("Enter the co-ordinates to be checked: ");
    scanf(" %d %d", &a, &b);
    if((a>=x && a<=(x+l)) && (b>=y && b<=(y+l))) //boundary limits for four sides of the square
    {
        printf("\n%d,%d lies inside the square.", a,b);
    }
    else
    {
        printf("\n%d,%d don't lie inside the square.", a,b);
    }
    return 0;   
}

在此处输入图像描述

然后程序在接受输入后结束。请帮我解决VS Code的这个问题。

标签: cvisual-studio-codevscode-settings

解决方案


您对骨灰盒进行编程,但窗口将关闭,因为它会退出。程序结束后,您需要保持窗口打开:

{ "cpp": "g++ $fullFileName -o $fileNameWithoutExt.exe && start /wait $fileNameWithoutExt.exe" }

命令 start 的 /wait 选项将使用 /k 选项运行命令提示符,以确保这一点。


推荐阅读