i have this file called main.cpp
#include <iostream>
#include <fstream>
#include <sstream>
#include "headers/lexer.hpp"
int main(int argc, char **argv)
{
if (argc < 2)
{
std::cout << "Please provide a file";
exit(1);
}
std::cout << "Reading from: " << argv[1] << std::endl;
std::ifstream mainFile(argv[1]);
std::stringstream buf;
char t;
while (mainFile.get(t))
buf << t;
std::string orgCode = buf.str();
std::cout << "The code is:" << std::endl
<< orgCode;
Lexer lexer(orgCode);
std::cout << std::endl
<< "Reached the end of the program";
return 0;
}
with this header file lexer.hpp in a “headers” directory
#ifdef __LEXER_H
#define __LEXER_H
#include <string>
class lexer
{
public:
Lexer(std::string sourceCode)
{
source = sourceCode;
cursor = 0;
size = sourceCode.length();
curr = sourceCode.at(cursor);
}
private:
std::string source;
int cursor;
int size;
char curr;
};
#endif
this is the tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe build active file",
"command": "C:\msys64\mingw64\bin\g++.exe",
"args": [
"${workspaceFolder}/*.cpp",
"-o",
"${fileDirname}\${fileBasenameNoExtension}",
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "compiler: C:\msys64\mingw64\bin\g++.exe"
}
]
}
and this this the c_cpp_proporties.json file:
`{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "C:\msys64\mingw64\bin\gcc.exe",
"cStandard": "c17",
"cppStandard": "gnu++17",
"intelliSenseMode": "windows-gcc-x64"
}
],
"version": 4
}`
the problem is that the line Lexer lexer(orgCode);
give an error identifier "Lexer" is undefined
I have searched a lot and did not find a solution.
i have tried messing with the tasks.json file and the c_cpp_proporties.json file, but no matter what i did it did not work, like i changed the path a couple of time, and in the includePath
i also tried to include a couple of direct paths to the header file, added in the args
more args and still did not work
Ataba is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.