怎样在windows本地使用gcc、g++、gdb、make

1、切换到D盘:
输入盘符+冒号:在命令行中输入“D:”(不包含引号)。
使用CD命令:输入“cd /d D:\”(不包含引号),其中“/d”表示切换到指定盘符,D:\表示D盘根目录。
2、编译:g++ test.cpp -o test.exe
在这里插入图片描述
3、查看当前文件:dir
4、将mingw32-make.exe拷贝并重命名为make.exe,否则在cmd中输入make会报错误:
‘make’ is not recognized as an internal or external command,
operable program or batch file.
在这里插入图片描述
5、将编译好的文件通过gdb运行
在这里插入图片描述
6 VS code里面可编译运行,
在这里插入图片描述
在这里插入图片描述
源码:

#include <iostream>
#include <array> // 引入头文件
using namespace std;
int main()
{    
// 创建一个长度为5的int数组
    array<int,5> arr = {2,4,6,8,10};
    cout << arr[0] << endl; // 2
    cout << arr[4] << endl; // 10
    arr[1] = 666;
    cout << arr.at(1) << endl; // 666
    // 普通循环
    for(int i=0;i<arr.size();i++)
    {
		  cout << arr.at(i) << " ";
    }
    cout << endl;
    // 给所有元素赋值
    arr.fill(5);
    // for-each循环
    for(int i:arr)
    {
      cout << i+2 << " ";
    }
    cout << endl;    // 迭代器:略
    while(1);
    return 0;
}

json文件配置如下:
launch.json

{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "C/C++: g++.exe build and debug active file",
      "type": "cppdbg",
      "request": "launch",
      "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
      "args": [],
      "stopAtEntry": false,
      "cwd": "C:/MinGW/bin",
      "environment": [],
      "externalConsole": false,
      "MIMode": "gdb",
      "miDebuggerPath": "C:\\MinGW\\bin\\gdb.exe",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        },
        {
          "description": "Set Disassembly Flavor to Intel",
          "text": "-gdb-set disassembly-flavor intel",
          "ignoreFailures": true
        }
      ],
      "preLaunchTask": "C/C++: gcc.exe build active file"
    },
    {
      "name": "C/C++ Runner: Debug Session",
      "type": "cppdbg",
      "request": "launch",
      "args": [],
      "stopAtEntry": false,
      "externalConsole": true,
      "cwd": "d:/gcc_gdb/cpp2",
      "program": "d:/gcc_gdb/cpp2/build/Debug/outDebug",
      "MIMode": "gdb",
      "miDebuggerPath": "gdb",
      "setupCommands": [
        {
          "description": "Enable pretty-printing for gdb",
          "text": "-enable-pretty-printing",
          "ignoreFailures": true
        }
      ]
    }
  ]
}

c_cpp_properties.json

{
  "configurations": [
    {
      "name": "windows-gcc-x86",
      "includePath": [
        "${workspaceFolder}/**"
      ],
      "compilerPath": "C:/MinGW/bin/gcc.exe",
      "cStandard": "${default}",
      "cppStandard": "${default}",
      "intelliSenseMode": "windows-gcc-x86",
      "compilerArgs": [
        ""
      ]
    }
  ],
  "version": 4
}

task.json

{
  "configurations": [
    {
      "name": "windows-gcc-x86",
      "includePath": [
        "${workspaceFolder}/**"
      ],
      "compilerPath": "C:/MinGW/bin/gcc.exe",
      "cStandard": "${default}",
      "cppStandard": "${default}",
      "intelliSenseMode": "windows-gcc-x86",
      "compilerArgs": [
        ""
      ]
    }
  ],
  "version": 4
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值