I am writing an interface for a program that will eventually be able to interpret another language. Right now I am trying to make it so if the user enters a phrase followed by () with text within the parentheses, then it will read it as a function and pass that phrase as a string into a function that opens files. When I isolate just that part into another testing program, it does not throw any error codes. But when I test it out in the program I need it to work in, it throws the following:
Severity Code Description Project File Line Suppression State
Error C2660 'Interface::read': function does not take 1 arguments pysub1
C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.cpp 50
Error C2511 'void Interface::read(std::string &)': overloaded member function not
found in
'Interface' pysub1 C:\Users\Johnathon\source\repos\pysub1\pysub1\interface.cpp 131
And here is the code: //
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include "interface.h"
using namespace std;
void Interface::startInterface()
{
string input, command, file;
do
{
std::cout << "PySUB Interpreter 1.0 on Windows (September 2022)" << endl;
std::cout << "Enter program lines or read(<filename>.py) at command line interface"
<< endl;
std::cout << "Type 'help' for more information or 'quit' to exit" << endl;
std::cin >> input;
if (input.back() == ')')//this checks to see if the user input is a function. the
idea here is that if it is a function, there will be a right-side paren.
{
for (int i = 0; i < input.length(); i++)
{
if (input[i] == '(')//checks for an opening parenthesis
{
if (input[i + 1] != ')')//makes sure that there isn't a closing paren.
directly after opening paren.
{
for (int k = i + 1; k < input.length() - 1; k++)//loop that
continues iterating after the opening paren. and stops just before the last character,
which is a closing paren.
{
command.push_back(input[k]);//pushes characters into string
variable to be passed into other functions.
}
}
else
{
break;//this checks to see if there is a corresponding parenthesis.
if there is not, the loop will break.
}
}
}
for (int j = 0; j < command.length(); j++)
{
filetype will include a '.'
{
break;
}
else
{
file = command;//if command is a filetype, file is now command and file
will be passed to the read function.
}
}//if command is a filetype, verify that the first 4 characters of input is
equal to read
if (!file.empty())//if file string is not empty, pass the file value into the
read function
{
read(file);
cin >> input;
}
}
if (input == "help")
{
help();
}
else if (input == "show")
{
show();
}
} while (input != "quit");
}
void Interface::help()
{
{
string input;
std::cout << ">>> Help" << endl;
std::cout << "Welcome to the help utility!" << endl;
std::cout << "* To exit and return to the interpreter, type 'exit" << endl;
std::cout << "* To get a list of commands, type 'commands'" << endl;
std::cout << "* To get a description of any command, just type the command at the
help> prompt" << endl;
do
{
std::cout << "help>";
std::cin >> input;
if (input == "commands")
{
std::cout << "Below is a list of commands. Enter any command at the promp
to get more help" << endl;
std::cout << " " << endl;
std::cout << "clear help quit" << endl;
std::cout << "read show" << endl;
std::cout << " " << endl;
std::cout << "NOTE: All commands can also be entered as functions:" <<
endl;
std::cout << " " << endl;
std::cout << " " << endl;
std::cout << "clear() help() quit()" << endl;
std::cout << "read() show()" << endl;
}
else if (input == "clear" || input == "clear()")
{
std::cout << "This command clears out or deletes any lines that are stored
in the program data structure." << endl;
}
else if (input == "help" || input == "help()")
{
std::cout << "This command will enter the help utility." << endl;
}
else if (input == "quit" || input == "quit()")
{
std::cout << "This command exits the command line interpreter." << endl;
}
else if (input == "read" || input == "read()")
{
std::cout << "This command reads a file to be interpreted." << endl;
}
else if (input == "show")
{
std::cout << "This command shows the results from a file that was read.
This must be used in conjunction with the 'read' command." << endl;
}
} while (input != "exit");
}
}
void Interface::show()
{
}
void Interface::read(string& var)
{
ifstream ofile;
string line;
ofile.open(file);
cout << "Reading data from the file.\n";
if (ofile.is_open())
{
while (getline(ofile, line))
{
printf("%s", line.c_str());
}
ofile.close();
}
}
void Interface::clear()
{
}
int main()
{
Interface pySubInterpreter;
// Start the interface
pySubInterpreter.startInterface();
return 0;
}
And the following is the header file
#ifndef INTERFACE_H
#define INTERFACE_H
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
class Interface
{
private:
typedef std::vector<std::string> programType;
programType programCode;
public:
void startInterface();
void quit();
void help();
void show();
void read(string& var);
void clear();
};
#endif