I am a beginner in learning c++.And here are the details: this is the _test.cpp
#include <iostream>
#include "cat.h"
using namespace std;
int main() {
speak();
}
and cat.h
#pragma once
void speak();
cat.cpp
#include "cat.h"
#include <iostream>
void speak() {
std::cout << "meow!!" << std::endl;
}
when I use a powershell to compile them, it's ok.
But when i try to CompileRun the _test.cpp, the errors come. enter image description here
when I CompileRun the cat.cpp, it tells me : enter image description here
And here are my tasks.json and launch.json:
{
"version": "2.0.0",
"tasks": [
/*{
"type": "shell",
"label": "compile",
"command": "g++",
"args": [
"-g",
"${workspaceFolder}\\*.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"problemMatcher": [
"$gcc"
],
"group": "build"
},*/
{
"type": "cppbuild",
"label": "C/C++: gcc.exe ",
"command": "C:\\MinGW\\bin\\gcc.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}\\*.cpp",
//"${workspaceFolder}\\*.h",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
]
}
{
"version": "0.2.0",
"configurations": [
{
"name": "C/C++",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Test",
"text": "python import sys;sys.path.insert(0, 'C:\\MinGW\\share\\gcc-11.2.0\\python');sys.path.insert(0, 'E:\\mingw64\\share\\gdb\\python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)",
"ignoreFailures": true
},
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "gdb.exe",
"preLaunchTask": "compile",
},
]
}
I have searched related questions on youtube and google and have viewed some posts on stackoverflow. So I have modified tasks.json and launch.json. But I can't solve the questions I was wondering if there is a way for me to just run the _test.cpp file and it works!
Aucun commentaire:
Enregistrer un commentaire