I'm relative new and recently started learning OOPS from an online course, The problem I m facing with VSCODE is that I'm not able to create separate files for a single bulky code. I came across some solutions on stack overflow itself and I modified my task.json and launch.json accordingly.
Now the compiler is able find all the related files to the main.cpp, but when I try to run and build my code it says "Error Exists after running preLaunchTask 'C/C++:gcc.exe build active file;.
here is the source code below
main.cpp
#include <iostream>
#include "Account.h"
using namespace std;
int main() {
Account frank_account;
frank_account.set_name("Frank's account");
return 0;
}
account.cpp
#include "Account.h"
void Account::set_name(std::string n) {
name = n;
}
std::string Account::get_name() {
return name;
}
account.h
#ifndef _ACCOUNT_H_
#define _ACCOUNT_H_
#include <string>
class Account
{
private:
// attributes
std::string name;
double balance;
public:
void set_name(std::string n);
std::string get_name();
};
#endif
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\\ProgramData\\chocolatey\\bin\\g++.exe",
"args": [
"-g",
"${fileDirname}\\**.cpp",
"${fileDirname}\\**.h",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"skipFiles": ["<node_internals>/**"],
"program": "${file}",
"preLaunchTask": "g++.exe build active file"
}
]
}
On running main.cpp I get this error "Error Exists after running preLaunchTask 'C/C++:gcc.exe build active file;. I Click on debug anyway so it says main does not exist
my terminal says fatal error: string: No such file or directory 3 | #include