windows vscode mingw c++入門(2)
導包
新建文件夾 first
- 與 mian.cpp 同級新建文件夾 first
- 新建兩個文件
- q.h
#pragma once // 防止重複導入 void q1();
- q.cpp
#include <iostream> using namespace std; #include "q.h" void q1() { cout << "導入 q.q1 成功" << endl; }
tasks.json 修改
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "g++.exe build active file",
"command": "C:\\mingw32\\bin\\g++.exe",
"args": [// 只要修改這裏
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe",
"-I", //包含頭目錄
"D:\\CodeHome\\cpp\\myfirst\\first", //頭目錄路徑
"D:\\CodeHome\\cpp\\myfirst\\first\\q.cpp" //不想一個個編譯成 .o文件,直接包含 cpp 文件
],
"options": {
"cwd": "C:\\mingw32\\bin"
},
"problemMatcher": [
"$gcc"
],
"group": "build"
}
]
}
ctrl + shift + p , 搜索 c++ , c++ config… json,生成 c_cpp_properties.json,新建也行
{
"configurations": [
{
"name": "Win32",
"includePath": [ // 包含的 c++ 頭文件,包含進來編譯器才能自動補全代碼
"${workspaceFolder}/**",
"C:\\mingw32\\include",
"D:\\CodeHome\\cpp\\myfirst\\first"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\\mingw32\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x86"
}
],
"version": 4
}