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
}